int MP3ImportFileHandle::Import(TrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags) { outTracks.clear(); CreateProgress(); /* Prepare decoder data, initialize decoder */ mPrivateData.file = mFile; mPrivateData.inputBuffer = new unsigned char [INPUT_BUFFER_SIZE]; mPrivateData.progress = mProgress.get(); mPrivateData.updateResult= eProgressSuccess; mPrivateData.id3checked = false; mPrivateData.numChannels = 0; mPrivateData.trackFactory= trackFactory; mad_decoder_init(&mDecoder, &mPrivateData, input_cb, 0, 0, output_cb, error_cb, 0); /* and send the decoder on its way! */ bool res = (mad_decoder_run(&mDecoder, MAD_DECODER_MODE_SYNC) == 0) && (mPrivateData.numChannels > 0) && !(mPrivateData.updateResult == eProgressCancelled) && !(mPrivateData.updateResult == eProgressFailed); mad_decoder_finish(&mDecoder); delete[] mPrivateData.inputBuffer; if (!res) { /* failure */ /* printf("failure\n"); */ return (mPrivateData.updateResult); } /* success */ /* printf("success\n"); */ /* copy the WaveTrack pointers into the Track pointer list that * we are expected to fill */ for(const auto &channel : mPrivateData.channels) { channel->Flush(); } outTracks.swap(mPrivateData.channels); /* Read in any metadata */ ImportID3(tags); return mPrivateData.updateResult; }
int MP3ImportFileHandle::Import(TrackFactory *trackFactory, Track ***outTracks, int *outNumTracks, Tags *tags) { int chn; CreateProgress(); /* Prepare decoder data, initialize decoder */ mPrivateData.file = mFile; mPrivateData.inputBuffer = new unsigned char [INPUT_BUFFER_SIZE]; mPrivateData.progress = mProgress; mPrivateData.channels = NULL; mPrivateData.cancelled = false; mPrivateData.id3checked = false; mPrivateData.numChannels = 0; mPrivateData.trackFactory= trackFactory; mad_decoder_init(&mDecoder, &mPrivateData, input_cb, 0, 0, output_cb, error_cb, 0); /* and send the decoder on its way! */ bool res = (mad_decoder_run(&mDecoder, MAD_DECODER_MODE_SYNC) == 0) && (mPrivateData.numChannels > 0) && (!mPrivateData.cancelled); mad_decoder_finish(&mDecoder); delete[] mPrivateData.inputBuffer; if (!res) { /* failure */ /* printf("failure\n"); */ /* delete everything */ for (chn = 0; chn < mPrivateData.numChannels; chn++) { delete mPrivateData.channels[chn]; } delete[] mPrivateData.channels; return (mPrivateData.cancelled ? eImportCancelled : eImportFailed); } /* success */ /* printf("success\n"); */ /* copy the WaveTrack pointers into the Track pointer list that * we are expected to fill */ *outNumTracks = mPrivateData.numChannels; *outTracks = new Track* [mPrivateData.numChannels]; for(chn = 0; chn < mPrivateData.numChannels; chn++) { mPrivateData.channels[chn]->Flush(); (*outTracks)[chn] = mPrivateData.channels[chn]; } delete[] mPrivateData.channels; /* Read in any metadata */ ImportID3(tags); return eImportSuccess; }