rpcli: fix mp3 decoding
This commit is contained in:
@@ -331,6 +331,7 @@ static int decode_mpeg_audio_to_wav(const char *inputPath,
|
|||||||
mp3dec_frame_info_t info;
|
mp3dec_frame_info_t info;
|
||||||
mp3d_sample_t pcm[MINIMP3_MAX_SAMPLES_PER_FRAME];
|
mp3d_sample_t pcm[MINIMP3_MAX_SAMPLES_PER_FRAME];
|
||||||
int samples = mp3dec_decode_frame(&dec, inputData + pos, (int)(inputSize - pos), pcm, &info);
|
int samples = mp3dec_decode_frame(&dec, inputData + pos, (int)(inputSize - pos), pcm, &info);
|
||||||
|
int totalSamples;
|
||||||
|
|
||||||
if (info.frame_bytes <= 0) {
|
if (info.frame_bytes <= 0) {
|
||||||
++pos;
|
++pos;
|
||||||
@@ -342,6 +343,15 @@ static int decode_mpeg_audio_to_wav(const char *inputPath,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.channels <= 0) {
|
||||||
|
fclose(out);
|
||||||
|
DeleteFileA(outputPath);
|
||||||
|
free(inputData);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalSamples = samples * info.channels;
|
||||||
|
|
||||||
if (!haveAudio) {
|
if (!haveAudio) {
|
||||||
sampleRate = info.hz;
|
sampleRate = info.hz;
|
||||||
channels = info.channels;
|
channels = info.channels;
|
||||||
@@ -355,18 +365,18 @@ static int decode_mpeg_audio_to_wav(const char *inputPath,
|
|||||||
|
|
||||||
if (gainScale != 1.0) {
|
if (gainScale != 1.0) {
|
||||||
int sampleIndex;
|
int sampleIndex;
|
||||||
for (sampleIndex = 0; sampleIndex < samples; ++sampleIndex) {
|
for (sampleIndex = 0; sampleIndex < totalSamples; ++sampleIndex) {
|
||||||
pcm[sampleIndex] = apply_gain_sample(pcm[sampleIndex], gainScale);
|
pcm[sampleIndex] = apply_gain_sample(pcm[sampleIndex], gainScale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwrite(pcm, sizeof(mp3d_sample_t), (size_t)samples, out) != (size_t)samples) {
|
if (fwrite(pcm, sizeof(mp3d_sample_t), (size_t)totalSamples, out) != (size_t)totalSamples) {
|
||||||
fclose(out);
|
fclose(out);
|
||||||
DeleteFileA(outputPath);
|
DeleteFileA(outputPath);
|
||||||
free(inputData);
|
free(inputData);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
dataBytes += (unsigned)(samples * sizeof(mp3d_sample_t));
|
dataBytes += (unsigned)(totalSamples * sizeof(mp3d_sample_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(inputData);
|
free(inputData);
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user