本文介绍了如何降低Linux上的wav文件的质量和规格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以要preface我的问题,我给一些背景。

在SDL2可以加载WAV文件,如从:

  SDL_AudioSpec wav_spec;
UINT32 wav_length;
UINT8 * wav_buffer;/ *加载WAV * /
如果(SDL_LoadWAV(test.wav,&安培; wav_spec,&安培; wav_buffer,&安培; wav_length)== NULL){
    fprintf中(标准错误,无法打开test.wav:%S \\ n,SDL_GetError());
}其他{
    / *做的东西与WAV数据,然后... * /
    SDL_FreeWAV(wav_buffer);
}

我是从得到的问题是复合WAVE文件不支持


现在我打算打开wav文件具有以下属性:

 播放test.wav。
检测到的文件格式:WAV / WAVE(波形音频)(libavformat)时
ID_AUDIO_ID = 0
[lavf]流0:音频(pcm_s24le),-aid 0
剪辑信息:
 EN coded_by:Pro Tools的
ID_CLIP_INFO_NAME0 = EN coded_by
ID_CLIP_INFO_VALUE0 =的Pro Tools
 originator_reference:
ID_CLIP_INFO_NAME1 = originator_reference
ID_CLIP_INFO_VALUE1 =
 日期:2016年5月1日
ID_CLIP_INFO_NAME2 =日期
ID_CLIP_INFO_VALUE2 = 2016年5月1日
 CREATION_TIME:20点13分34秒
ID_CLIP_INFO_NAME3 = CREATION_TIME
ID_CLIP_INFO_VALUE3 = 20:13:34
 time_reference:
ID_CLIP_INFO_NAME4 = time_reference
ID_CLIP_INFO_VALUE4 =
ID_CLIP_INFO_N = 5
在DIR加载字幕/
ID_FILENAME = DIR / test.wav
ID_DEMUXER = lavf preF
ID_AUDIO_FORMAT = 1
ID_AUDIO_BITRATE = 2304000
ID_AUDIO_RATE = 48000
ID_AUDIO_NCH = 2
ID_START_TIME = 0.00
ID_LENGTH = 135.53
ID_SEEKABLE = 1
ID_CHAPTERS = 0
选择的音频codeC:Uncom pressed PCM [PCM]
音频:48000赫兹,2通道,s24le,2304.0千比特/ 100.00%(比例:288000-> 288000)
ID_AUDIO_BITRATE = 2304000
ID_AUDIO_RATE = 48000
ID_AUDIO_NCH = 2
AO:[脉冲] 48000Hz 2CH s16le(每个样品2个字节)
ID_AUDIO_ codeC = PCM

从wiki.libsdl.org/SDL_OpenAudioDevice页面以及wiki.libsdl.org/SDL_AudioSpec#Remarks页我至少可以猜测的wav文件:

  =频率48000;
格式= AUDIO_F32;
通道= 2;
样本= 4096;

质量应该工作。

我能看到的主要问题是,我的wav文件有 s16le 格式,而它不是SDL_AudioSpec页面上列出。

这使我相信我需要减​​少test.wav的质量,因此它不会显示为复杂的SDL。

当我搜索引擎复合波形文件不支持什么有益的出现,但它出现在SDL_Mixer库,据我知道我没有使用。

能否通过格式进行ffmepg改变了SDL2工作?

编辑:这似乎是在SDL2实际code在那里抱怨。我真的不知道有足够的了解C到挖通了广大SDL2库中的所有方法,但我想,如果有人注意到一些刚从提示变量名称和它可以帮助这样的:

  / *读取的音频数据格式块* /
chunk.data = NULL;
做{
    如果(chunk.data!= NULL){
        SDL_free(chunk.data);
        chunk.data = NULL;
    }
    lenread = ReadChunk(SRC,&安培;块);
    如果(lenread℃,){
        was_error = 1;
        后藤做的;
    }
    / * 2 UINT32对块头+ LEN,加上lenread * /
    headerDiff + = lenread + 2 * sizeof的(UINT32);
}而((chunk.magic == FACT)||(chunk.magic == LIST));/ *德code中的音频数据格式* /
格式=(WaveFMT *)chunk.data;
如果(chunk.magic!= FMT){
    SDL_SetError(复杂的波形文件不支持);
    was_error = 1;
    后藤做的;
}


解决方案

有趣的音频几个小时转换我得到了它的工作之后,将不得不调整它,试图得到更好的音质。

要回答眼下的问题,转换可以这样做:

 的ffmpeg -i old.wav -a codeC pcm_s16le -ac 1 -ar 16000 new.wav

要找到您的版本的ffmpeg codeCS:

 的ffmpeg  -  codeCS

此格式适用于SDL。

下一页SDL内设定时的所需SDL_AudioSpec 的确保有正确的设置:

  =频率16000;
格式= AUDIO_S16LSB;
通道= 2;
样本= 4096;

最后,主要的问题是最有可能使用传统的 SDL_MixAudio ,而不是较新的 SDL_MixAudioFormat

通过以​​下设置:

SDL_MixAudioFormat(流mixData,AUDIO_S16LSB,LEN,SDL_MIX_MAXVOLUME / 2); 作为可以在wiki上找到

So to preface my problem, I'll give some context.

In SDL2 you can load wav files such as from the wiki:

SDL_AudioSpec wav_spec;
Uint32 wav_length;
Uint8 *wav_buffer;

/* Load the WAV */
if (SDL_LoadWAV("test.wav", &wav_spec, &wav_buffer, &wav_length) == NULL) {
    fprintf(stderr, "Could not open test.wav: %s\n", SDL_GetError());
} else {
    /* Do stuff with the WAV data, and then... */
    SDL_FreeWAV(wav_buffer);
}

The issue I'm getting from SDL_GetError is Complex WAVE files not supported


Now the wav file I'm intending to open has the following properties:

Playing test.wav.
Detected file format: WAV / WAVE (Waveform Audio) (libavformat)
ID_AUDIO_ID=0
[lavf] stream 0: audio (pcm_s24le), -aid 0
Clip info:
 encoded_by: Pro Tools
ID_CLIP_INFO_NAME0=encoded_by
ID_CLIP_INFO_VALUE0=Pro Tools
 originator_reference:
ID_CLIP_INFO_NAME1=originator_reference
ID_CLIP_INFO_VALUE1=
 date: 2016-05-1
ID_CLIP_INFO_NAME2=date
ID_CLIP_INFO_VALUE2=2016-05-1
 creation_time: 20:13:34
ID_CLIP_INFO_NAME3=creation_time
ID_CLIP_INFO_VALUE3=20:13:34
 time_reference:
ID_CLIP_INFO_NAME4=time_reference
ID_CLIP_INFO_VALUE4=
ID_CLIP_INFO_N=5
Load subtitles in dir/
ID_FILENAME=dir/test.wav
ID_DEMUXER=lavfpref
ID_AUDIO_FORMAT=1
ID_AUDIO_BITRATE=2304000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=2
ID_START_TIME=0.00
ID_LENGTH=135.53
ID_SEEKABLE=1
ID_CHAPTERS=0
Selected audio codec: Uncompressed PCM [pcm]
AUDIO: 48000 Hz, 2 ch, s24le, 2304.0 kbit/100.00% (ratio: 288000->288000)
ID_AUDIO_BITRATE=2304000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=2
AO: [pulse] 48000Hz 2ch s16le (2 bytes per sample)
ID_AUDIO_CODEC=pcm

From the wiki.libsdl.org/SDL_OpenAudioDevice page and subsequent wiki.libsdl.org/SDL_AudioSpec#Remarks page I can at least surmise that a wav file of:

freq = 48000;
format = AUDIO_F32;
channels = 2;
samples = 4096;

quality should work.

The main problem I can see is that my wav file has the s16le format whereas it's not listed on the SDL_AudioSpec page.

This leads me to believe I need to reduce the quality of test.wav so it does not appear as "complex" in SDL.

When I search engine Complex WAVE files not supported nothing helpful comes up, except it appears in the SDL_Mixer library, which as far as I know I'm not using.

Can the format be changed via ffmepg to work in SDL2?

Edit: This appears to be the actual code in SDL2 where it complains. I don't really know enough about C to dig all the way through the vast SDL2 library, but I thought it might help if someone notices something just from hinting variable names and such:

/* Read the audio data format chunk */
chunk.data = NULL;
do {
    if ( chunk.data != NULL ) {
        SDL_free(chunk.data);
        chunk.data = NULL;
    }
    lenread = ReadChunk(src, &chunk);
    if ( lenread < 0 ) {
        was_error = 1;
        goto done;
    }
    /* 2 Uint32's for chunk header+len, plus the lenread */
    headerDiff += lenread + 2 * sizeof(Uint32);
} while ( (chunk.magic == FACT) || (chunk.magic == LIST) );

/* Decode the audio data format */
format = (WaveFMT *)chunk.data;
if ( chunk.magic != FMT ) {
    SDL_SetError("Complex WAVE files not supported");
    was_error = 1;
    goto done;
}
解决方案

After a couple hours of fun audio converting I got it working, will have to tweak it to try and get better sound quality.

To answer the question at hand, converting can be done by:

ffmpeg -i old.wav -acodec pcm_s16le -ac 1 -ar 16000 new.wav

To find codecs on your version of ffmpeg:

ffmpeg -codecs

This format works with SDL.

Next within SDL when setting the desired SDL_AudioSpec make sure to have the correct settings:

freq = 16000;
format = AUDIO_S16LSB;
channels = 2;
samples = 4096;

Finally the main issue was most likely using the legacy SDL_MixAudio instead of the newer SDL_MixAudioFormat

With the following settings:

SDL_MixAudioFormat(stream, mixData, AUDIO_S16LSB, len, SDL_MIX_MAXVOLUME / 2); as can be found on the wiki.

这篇关于如何降低Linux上的wav文件的质量和规格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 18:33
查看更多