9 #include <taglib/fileref.h>
10 #include <taglib/tag.h>
23 int mins = (
mLength - secs) / 60;
26 sprintf(dur,
"%d:0%d", mins, secs);
28 sprintf(dur,
"%d:%d", mins, secs);
29 logMsg(
"Tags: \"%s\" - %s - %s - %d - %s min",
31 logMsg(
" trk %d - %s - %d kbps - %d Hz - %d ch",
43 mMode(kSoundFileClosed),
58 mProperties(otherSndFile.mProperties),
59 mMode(otherSndFile.mode()),
60 mIsValid(otherSndFile.isValid()),
61 mIsLooping(otherSndFile.isLooping()),
62 mStart(otherSndFile.startFrame()),
63 mStop(otherSndFile.stopFrame()),
64 mRate(otherSndFile.playbackRate()),
65 mBase(otherSndFile.mBase) {
126 mNumChannels = numChans;
137 logMsg(
"Abst_SoundFile::mergeToMono - buffers not allocated");
141 logMsg(
"Abst_SoundFile::mergeToMono - sound file already mono");
150 for (
unsigned j = 0; j < numCh; j++)
218 this->
addInput(CSL_RATE, frequency);
226 logMsg(
"FrequencyAmount::set scale input value");
270 TagLib::FileRef tfil(
mPath.c_str());
271 if ( ! tfil.isNull() && tfil.tag()) {
272 TagLib::Tag *tag = tfil.tag();
281 if( ! tfil.isNull() && tfil.audioProperties()) {
282 TagLib::AudioProperties *properties = tfil.audioProperties();
288 return !tfil.isNull();
297 const char * nam =
path().c_str();
298 if (strlen(nam) > 50)
299 logMsg(
"SndFile \"%s\"\n\t\t%d Hz, %d ch, %5.3f sec",
302 logMsg(
"SndFile \"%s\" - %d Hz, %d ch, %5.3f sec",
309 unsigned numFrames = outputBuffer.mNumFrames;
310 unsigned currentFrame = mCurrentFrame;
313 if (currentFrame >= (
unsigned) mStop) {
314 outputBuffer.zeroBuffers();
317 if (currentFrame + numFrames >= (
unsigned) mStop) {
318 numFrames = mStop - currentFrame;
319 outputBuffer.zeroBuffers();
321 if ( ! this->isCached(numFrames)) {
322 this->readBufferFromFile(numFrames);
328 if (scalePort->isFixed() && offsetPort->isFixed()
329 && (scaleValue == 1) && (offsetValue == 0)) {
330 unsigned numBytes = numFrames *
sizeof(
sample);
331 for (
unsigned i = 0; i < outputBuffer.mNumChannels; i++) {
332 int which =
csl_min(i, (mNumChannels - 1));
333 SampleBuffer sndPtr = mWavetable.monoBuffer(which) + currentFrame;
335 memcpy(outPtr, sndPtr, numBytes);
339 for (
unsigned i = 0; i < outputBuffer.mNumChannels; i++) {
342 for (
unsigned j = 0; j < numFrames; j++) {
343 samp = (*dPtr++ * scaleValue) + offsetValue;
347 scalePort->resetPtr();
348 offsetPort->resetPtr();
353 this->setFrequency(mRate);
354 for (
unsigned i = 0; i < mNumChannels; i++)
357 currentFrame += numFrames;
358 if ((currentFrame >= (
unsigned) mStop) && mIsLooping)
360 mCurrentFrame = currentFrame;
395 unsigned start, stop;
397 if(fscanf(input,
"%s %u %u\n", cmName, &start, &stop) == 3) {
408 logMsg(
"\tSC: \"%s\" %d - %d (%.3f)\n",
418 unsigned numFrames = outputBuffer.mNumFrames;
419 unsigned toCopy = 0, toZero;
422 for (
unsigned h = 0; h < outputBuffer.mNumChannels; h++) {
423 out = outputBuffer.buffer(h);
424 if (mCurrent >= mStop) {
425 for (
unsigned i = 0; i < numFrames; i++)
429 SampleBuffer samps = (mFile->mWavetable.monoBuffer(0)) + (mCurrent * mFile->channels()) + h;
430 if ( ! mFile->isValid()) {
431 fprintf(stderr,
"\tCannot play uncached sound file \"%s\"n", mName.c_str());
432 for (
unsigned i = 0; i < numFrames; i++)
438 if ((mCurrent + numFrames) >= (unsigned) mStop) {
439 toCopy = mStop - mCurrent;
440 toZero = numFrames - toCopy;
443 for (
unsigned i = 0; i < toCopy; i++)
445 for (
unsigned i = 0; i < toZero; i++)
469 #ifdef USE_SNDFILEBUFFER
479 SoundFileBuffer::SoundFileBuffer(
string path,
unsigned numFrames)
488 mAreBuffersAllocated =
true;
489 mDidIAllocateBuffers =
false;
502 SoundFileBuffer::~SoundFileBuffer() { }
507 sample * SoundFileBuffer::samplePtrFor(
unsigned channel,
unsigned offset){
508 if ((mFile->base() <= offset) && (mFile->base() + mFile->cacheSize() > offset))
509 return(mFile->mWavetable.buffer(channel) + (offset - mFile->base()));
511 mFile->seekTo(offset);
512 mFile->readBufferFromFile(mFile->mWavetable.mNumFrames);
513 return(mFile->mWavetable.buffer(channel));
520 sample * SoundFileBuffer::samplePtrFor(
unsigned channel,
unsigned offset,
unsigned maxFrame){
521 if ((mFile->base() <= offset) && ((mFile->base() + mNumAlloc) > (offset + maxFrame)))
522 return (mFile->mWavetable.buffer(channel) + (offset - mFile->base()));
524 mFile->seekTo(offset);
525 mFile->readBufferFromFile(mFile->mWavetable.mNumFrames);
526 return(mFile->mWavetable.buffer(channel));
549 SampleFile::SampleFile() {
553 SampleFile::SampleFile(
string tpath,
unsigned MIDIKey,
double frequency,
double minRatio,
double maxRatio) {
557 SampleFile::~SampleFile() {