int SampleChannel::load(const char *file) { if (strcmp(file, "") == 0 || gIsDir(file)) { gLog("[SampleChannel] file not specified\n"); return SAMPLE_LEFT_EMPTY; } if (strlen(file) > FILENAME_MAX) return SAMPLE_PATH_TOO_LONG; Wave *w = new Wave(); if (!w->open(file)) { gLog("[SampleChannel] %s: read error\n", file); delete w; return SAMPLE_READ_ERROR; } if (w->channels() > 2) { gLog("[SampleChannel] %s: unsupported multichannel wave\n", file); delete w; return SAMPLE_MULTICHANNEL; } if (!w->readData()) { delete w; return SAMPLE_READ_ERROR; } if (w->channels() == 1) /** FIXME: error checking */ wfx_monoToStereo(w); if (w->rate() != G_Conf.samplerate) { gLog("[SampleChannel] input rate (%d) != system rate (%d), conversion needed\n", w->rate(), G_Conf.samplerate); w->resample(G_Conf.rsmpQuality, G_Conf.samplerate); } pushWave(w); /* sample name must be unique. Start from k = 1, zero is too nerdy */ std::string oldName = wave->name; int k = 1; while (!mh_uniqueSamplename(this, wave->name.c_str())) { wave->updateName((oldName + "-" + gItoa(k)).c_str()); k++; } gLog("[SampleChannel] %s loaded in channel %d\n", file, index); return SAMPLE_LOADED_OK; }
SampleChannel *mh_startInputRec() { /* search for the next available channel */ SampleChannel *chan = NULL; for (unsigned i=0; i<G_Mixer.channels.size; i++) { if (G_Mixer.channels.at(i)->type == CHANNEL_SAMPLE) if (((SampleChannel*) G_Mixer.channels.at(i))->canInputRec()) { chan = (SampleChannel*) G_Mixer.channels.at(i); break; } } /* no chans available? */ if (chan == NULL) return NULL; Wave *w = new Wave(); if (!w->allocEmpty(G_Mixer.totalFrames)) return NULL; /* increase lastTakeId until the sample name TAKE-[n] is unique */ char name[32]; sprintf(name, "TAKE-%d", G_Patch.lastTakeId); while (!mh_uniqueSamplename(chan, name)) { G_Patch.lastTakeId++; sprintf(name, "TAKE-%d", G_Patch.lastTakeId); } chan->allocEmpty(G_Mixer.totalFrames, G_Patch.lastTakeId); G_Mixer.chanInput = chan; /* start to write from the actualFrame, not the beginning */ /** FIXME: move this before wave allocation*/ G_Mixer.inputTracker = G_Mixer.actualFrame; gLog( "[mh] start input recs using chan %d with size %d, frame=%d\n", chan->index, G_Mixer.totalFrames, G_Mixer.inputTracker ); return chan; }