75 mAFReader(otherSndFile.mAFReader),
76 mAFWriter(otherSndFile.mAFWriter),
77 mIOFile(otherSndFile.mIOFile) { }
99 juce::String fmt =
mAFReader->getFormatName();
102 else if (fmt[0] ==
'W')
136 juce::String fname(mPath.c_str());
137 mIOFile =
new juce::File(fname);
138 if ( ! mIOFile->exists()) {
142 juce::AudioFormatManager formatManager;
143 formatManager.registerBasicFormats();
144 mAFReader = formatManager.createReaderFor(*mIOFile);
146 this->initFromSndfile();
154 unsigned numFrames = (unsigned) mAFReader->lengthInSamples;
156 this->readBufferFromFile(numFrames);
158 mCurrentFrame = mStart;
196 juce::String fname(mPath.c_str());
197 mIOFile =
new juce::File(fname);
198 mOutStream = mIOFile->createOutputStream().get();
199 juce::StringPairArray metaDict;
200 juce::AiffAudioFormat afmt;
201 juce::WavAudioFormat wfmt;
206 mAFWriter = afmt.createWriterFor(mOutStream, (
double) rate, tchannels, bitDepth, metaDict, 0);
209 mAFWriter = wfmt.createWriterFor(mOutStream, (
double) rate, tchannels, bitDepth, metaDict, 0);
213 throw IOError(
"Unsupported sound file format");
236 memset(sampleBufferPtr, 0, numFrames *
sizeof(
sample));
245 currentFrame += numFrames;
251 if (currentFrame > (
unsigned) mStop) {
252 unsigned numFramesRemaining = currentFrame -
mStop;
253 unsigned numFramesRead = numFrames - numFramesRemaining;
256 while (numFramesRead < numFrames) {
261 currentFrame += numFramesRead;
264 unsigned bytesToClear = numFramesRemaining *
sizeof(
sample);
267 memset(sampleBufferPtr, 0, bytesToClear);
291 if (this->isCached()) {
292 mCurrentFrame = position;
293 return mCurrentFrame;
297 whenceInt = position;
300 whenceInt = mCurrentFrame - position;
303 whenceInt = duration() - position;
306 whenceInt = SEEK_CUR;
307 logMsg(
"Error: Invalid position seek flag. Used kPositionCurrent.");
311 mOutStream->setPosition(whenceInt);
312 return mCurrentFrame;
318 unsigned numFrames = inputBuffer.mNumFrames;
319 unsigned numChans = inputBuffer.mNumChannels;
321 juce::AudioSampleBuffer asb(numChans, numFrames);
322 asb.setDataToReferTo (inputBuffer.buffers(),numChans, numFrames);
323 mAFWriter->writeFromAudioSampleBuffer (asb, 0, numFrames);
335 unsigned numFrames = inputBuffer.mNumFrames;
339 for (
unsigned i = 0; i < mNumChannels; i++)
345 throw IOError(
"Sound file write error");
347 for (
unsigned i = 0; i < mNumChannels; i++)
void writeBuffer(Buffer &inputBuffer)
write a buffer of data into the file
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
juce::AudioFormatReader * mAFReader
my reader
void logMsg(const char *format,...)
These are the public logging messages.
SeekPosition
Enumeration for seek flags.
#define kSoundFileFormatAIFF
unsigned mNumFrames
sample frames
JSoundFile(string path, int start=-1, int stop=-1)
C'tors.
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
SoundFileMode mMode
r/w mode
static unsigned maxSndFileFrames()
the max num frames that can be cached
#define kSoundFileRead
Sound file constants.
unsigned mFrameRate
trigger ignored here
virtual void setToEnd()
set to end position
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
unsigned duration() const
number of frames in the sound file
juce::File * mIOFile
my JUCE file
void readBufferFromFile(unsigned numFrames)
read a buffer from the file (possibly all of it)
void openForRead(bool load=true)
void openForWrite(SoundFileFormat format=kSoundFileFormatAIFF, unsigned channels=1, unsigned rate=44100, unsigned bitDepth=16)
Open a file for write. Default values are some common format.
bool mIsValid
is my file valid?
unsigned mBytesPerSample
the # of bytes per sample
#define kSoundFileFormatOther
void initFromSndfile()
read SF header
unsigned mCurrentFrame
where I currently am in the buffer
float sample
(could be changed to int, or double)
unsigned mNumChannels
my "expected" number of output channels
#define kSoundFileFormatWAV
virtual void freeBuffer()
free the file cache
bool mIsLooping
am i looping start-stop?
int mStop
starting/ending frames (or -1 if not used)
juce::AudioFormatWriter * mAFWriter
and my writer
Buffer mWavetable
the stored wave form
void close()
close file seek to some position
juce::FileOutputStream * mOutStream
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
void checkBuffer(unsigned numFrames)
allocate buffer lazily
SoundFileFormat format()
get format open file and get stats
Here's the abstract sound file reader/writer class, a sample player UGen. The concrete subclasses rep...
virtual SampleBuffer * buffers()
static JSoundFile * openSndfile(string path, int start=-1, int stop=-1, bool doRead=true)
Factory methods.
Base class of CSL exceptions (written upper-case). Has a string message.
SampleBuffer * SampleBufferArray
Multi-channel buffer data type.
unsigned seekTo(int position, SeekPosition whence)
sampleBufferPtr = mWavetable.buffer(channelIndex) + start;