1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-27 15:08:39 +01:00

Updated to build with later compiler versions

No functional changes.

(Heck, do we even need this anymore???)
This commit is contained in:
lllucius@gmail.com
2014-11-14 15:59:47 +00:00
parent 7237236298
commit d2bfb4ac4b

View File

@@ -240,159 +240,163 @@ int QTImportFileHandle::Import(TrackFactory *trackFactory,
UInt32 maxSampleSize; UInt32 maxSampleSize;
UInt32 numchan; UInt32 numchan;
UInt32 bufsize; UInt32 bufsize;
bool res = false;
CreateProgress(); CreateProgress();
err = MovieAudioExtractionBegin(mMovie, 0, &maer); do
if (err != noErr) {
wxMessageBox(_("Unable to start QuickTime extraction"));
goto done;
}
err = MovieAudioExtractionSetProperty(maer,
kQTPropertyClass_MovieAudioExtraction_Audio,
kQTMovieAudioExtractionAudioPropertyID_RenderQuality,
sizeof(quality),
&quality);
if (err != noErr) {
wxMessageBox(_("Unable to set QuickTime render quality"));
goto done;
}
err = MovieAudioExtractionSetProperty(maer,
kQTPropertyClass_MovieAudioExtraction_Movie,
kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
sizeof(discrete),
&discrete);
if (err != noErr) {
wxMessageBox(_("Unable to set QuickTime discrete channels property"));
goto done;
}
err = MovieAudioExtractionGetProperty(maer,
kQTPropertyClass_MovieAudioExtraction_Audio,
kQTAudioPropertyID_MaxAudioSampleSize,
sizeof(maxSampleSize),
&maxSampleSize,
NULL);
if (err != noErr) {
wxMessageBox(_("Unable to get QuickTime sample size property"));
goto done;
}
err = MovieAudioExtractionGetProperty(maer,
kQTPropertyClass_MovieAudioExtraction_Audio,
kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
sizeof(desc),
&desc,
NULL);
if (err != noErr) {
wxMessageBox(_("Unable to retrieve stream description"));
goto done;
}
numchan = desc.mChannelsPerFrame;
bufsize = 5 * desc.mSampleRate;
// determine sample format
sampleFormat format;
switch (maxSampleSize)
{ {
case 16: err = MovieAudioExtractionBegin(mMovie, 0, &maer);
format = int16Sample;
break;
case 24:
format = int24Sample;
break;
default:
format = floatSample;
break;
}
AudioBufferList *abl = (AudioBufferList *)
calloc(1, offsetof(AudioBufferList, mBuffers) + (sizeof(AudioBuffer) * numchan));
abl->mNumberBuffers = numchan;
WaveTrack **channels = new WaveTrack *[numchan];
int c;
for (c = 0; c < numchan; c++) {
abl->mBuffers[c].mNumberChannels = 1;
abl->mBuffers[c].mDataByteSize = sizeof(float) * bufsize;
abl->mBuffers[c].mData = malloc(abl->mBuffers[c].mDataByteSize);
channels[c] = trackFactory->NewWaveTrack(format);
channels[c]->SetRate(desc.mSampleRate);
if (numchan == 2) {
if (c == 0) {
channels[c]->SetChannel(Track::LeftChannel);
channels[c]->SetLinked(true);
}
else if (c == 1) {
channels[c]->SetChannel(Track::RightChannel);
}
}
}
do {
UInt32 flags = 0;
UInt32 numFrames = bufsize;
err = MovieAudioExtractionFillBuffer(maer,
&numFrames,
abl,
&flags);
if (err != noErr) { if (err != noErr) {
wxMessageBox(_("Unable to get fill buffer")); wxMessageBox(_("Unable to start QuickTime extraction"));
break; break;
} }
for (c = 0; c < numchan; c++) { err = MovieAudioExtractionSetProperty(maer,
channels[c]->Append((char *) abl->mBuffers[c].mData, floatSample, numFrames); kQTPropertyClass_MovieAudioExtraction_Audio,
} kQTMovieAudioExtractionAudioPropertyID_RenderQuality,
sizeof(quality),
numSamples += numFrames; &quality);
if (err != noErr) {
updateResult = mProgress->Update((wxULongLong_t)numSamples, wxMessageBox(_("Unable to set QuickTime render quality"));
(wxULongLong_t)totSamples);
if (numFrames == 0 || flags & kQTMovieAudioExtractionComplete) {
break; break;
} }
} while (updateResult == eProgressSuccess);
err = MovieAudioExtractionSetProperty(maer,
bool res = (updateResult == eProgressSuccess && err == noErr); kQTPropertyClass_MovieAudioExtraction_Movie,
kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
if (res) { sizeof(discrete),
for (c = 0; c < numchan; c++) { &discrete);
channels[c]->Flush(); if (err != noErr) {
wxMessageBox(_("Unable to set QuickTime discrete channels property"));
break;
} }
*outTracks = (Track **) channels; err = MovieAudioExtractionGetProperty(maer,
*outNumTracks = numchan; kQTPropertyClass_MovieAudioExtraction_Audio,
} kQTAudioPropertyID_MaxAudioSampleSize,
else { sizeof(maxSampleSize),
for (c = 0; c < numchan; c++) { &maxSampleSize,
delete channels[c]; NULL);
if (err != noErr) {
wxMessageBox(_("Unable to get QuickTime sample size property"));
break;
} }
delete [] channels; err = MovieAudioExtractionGetProperty(maer,
} kQTPropertyClass_MovieAudioExtraction_Audio,
kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
for (c = 0; c < numchan; c++) { sizeof(desc),
free(abl->mBuffers[c].mData); &desc,
} NULL);
free(abl); if (err != noErr) {
wxMessageBox(_("Unable to retrieve stream description"));
// break;
// Extract any metadata }
//
if (res) { numchan = desc.mChannelsPerFrame;
AddMetadata(tags); bufsize = 5 * desc.mSampleRate;
}
// determine sample format
sampleFormat format;
switch (maxSampleSize)
{
case 16:
format = int16Sample;
break;
case 24:
format = int24Sample;
break;
default:
format = floatSample;
break;
}
AudioBufferList *abl = (AudioBufferList *)
calloc(1, offsetof(AudioBufferList, mBuffers) + (sizeof(AudioBuffer) * numchan));
abl->mNumberBuffers = numchan;
WaveTrack **channels = new WaveTrack *[numchan];
int c;
for (c = 0; c < numchan; c++) {
abl->mBuffers[c].mNumberChannels = 1;
abl->mBuffers[c].mDataByteSize = sizeof(float) * bufsize;
abl->mBuffers[c].mData = malloc(abl->mBuffers[c].mDataByteSize);
channels[c] = trackFactory->NewWaveTrack(format);
channels[c]->SetRate(desc.mSampleRate);
if (numchan == 2) {
if (c == 0) {
channels[c]->SetChannel(Track::LeftChannel);
channels[c]->SetLinked(true);
}
else if (c == 1) {
channels[c]->SetChannel(Track::RightChannel);
}
}
}
do {
UInt32 flags = 0;
UInt32 numFrames = bufsize;
err = MovieAudioExtractionFillBuffer(maer,
&numFrames,
abl,
&flags);
if (err != noErr) {
wxMessageBox(_("Unable to get fill buffer"));
break;
}
for (c = 0; c < numchan; c++) {
channels[c]->Append((char *) abl->mBuffers[c].mData, floatSample, numFrames);
}
numSamples += numFrames;
updateResult = mProgress->Update((wxULongLong_t)numSamples,
(wxULongLong_t)totSamples);
if (numFrames == 0 || flags & kQTMovieAudioExtractionComplete) {
break;
}
} while (updateResult == eProgressSuccess);
bool res = (updateResult == eProgressSuccess && err == noErr);
if (res) {
for (c = 0; c < numchan; c++) {
channels[c]->Flush();
}
*outTracks = (Track **) channels;
*outNumTracks = numchan;
}
else {
for (c = 0; c < numchan; c++) {
delete channels[c];
}
delete [] channels;
}
for (c = 0; c < numchan; c++) {
free(abl->mBuffers[c].mData);
}
free(abl);
//
// Extract any metadata
//
if (res) {
AddMetadata(tags);
}
} while (false);
done: done:
@@ -405,8 +409,8 @@ done:
static const struct static const struct
{ {
OSType key; const OSType key;
wxChar *name; const wxChar *name;
} }
names[] = names[] =
{ {