mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 10:37:38 -04:00
test_codec: Fix some problems with writing WAV with DSP
On big-endian architecture, DSP output must be coverted to little- endian first. DSP output is also always interleaved stereo, 16 bit, NATIVE_FREQUENCY and wavinfo should be correct for this. Also, use standard clip_sample_16 already available. Change-Id: Ifa7b9fc77f0573070c7e79f059dc3000c437c42e
This commit is contained in:
parent
263955e3f0
commit
c51fe40a7d
1 changed files with 34 additions and 41 deletions
|
@ -245,14 +245,6 @@ static int process_dsp(const void *ch1, const void *ch2, int count)
|
||||||
return written_count;
|
return written_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int32_t clip_sample(int32_t sample)
|
|
||||||
{
|
|
||||||
if ((int16_t)sample != sample)
|
|
||||||
sample = 0x7fff ^ (sample >> 31);
|
|
||||||
|
|
||||||
return sample;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Null output */
|
/* Null output */
|
||||||
static void pcmbuf_insert_null(const void *ch1, const void *ch2, int count)
|
static void pcmbuf_insert_null(const void *ch1, const void *ch2, int count)
|
||||||
{
|
{
|
||||||
|
@ -303,6 +295,31 @@ static int fill_buffer(int new_offset){
|
||||||
|
|
||||||
/* WAV output or calculate crc32 of output*/
|
/* WAV output or calculate crc32 of output*/
|
||||||
static void pcmbuf_insert_wav_checksum(const void *ch1, const void *ch2, int count)
|
static void pcmbuf_insert_wav_checksum(const void *ch1, const void *ch2, int count)
|
||||||
|
{
|
||||||
|
/* Prevent idle poweroff */
|
||||||
|
rb->reset_poweroff_timer();
|
||||||
|
|
||||||
|
if (use_dsp) {
|
||||||
|
count = process_dsp(ch1, ch2, count);
|
||||||
|
wavinfo.totalsamples += count;
|
||||||
|
|
||||||
|
#ifdef ROCKBOX_BIG_ENDIAN
|
||||||
|
unsigned char* p = dspbuffer;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
int2le16(p,*(int16_t *)p);
|
||||||
|
p += 2;
|
||||||
|
int2le16(p,*(int16_t *)p);
|
||||||
|
p += 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (checksum) {
|
||||||
|
crc32 = rb->crc_32(dspbuffer, count * 2 * sizeof (int16_t), crc32);
|
||||||
|
} else {
|
||||||
|
rb->write(wavinfo.fd, dspbuffer, count * 2 * sizeof (int16_t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
const int16_t* data1_16;
|
const int16_t* data1_16;
|
||||||
const int16_t* data2_16;
|
const int16_t* data2_16;
|
||||||
|
@ -311,33 +328,7 @@ static void pcmbuf_insert_wav_checksum(const void *ch1, const void *ch2, int cou
|
||||||
unsigned char* p = wavbuffer;
|
unsigned char* p = wavbuffer;
|
||||||
const int scale = wavinfo.sampledepth - 15;
|
const int scale = wavinfo.sampledepth - 15;
|
||||||
const int dc_bias = 1 << (scale - 1);
|
const int dc_bias = 1 << (scale - 1);
|
||||||
int channels = (wavinfo.stereomode == STEREO_MONO) ? 1 : 2;
|
|
||||||
|
|
||||||
/* Prevent idle poweroff */
|
|
||||||
rb->reset_poweroff_timer();
|
|
||||||
|
|
||||||
if (use_dsp) {
|
|
||||||
count = process_dsp(ch1, ch2, count);
|
|
||||||
wavinfo.totalsamples += count;
|
|
||||||
if (channels == 1)
|
|
||||||
{
|
|
||||||
unsigned char *s = dspbuffer, *d = dspbuffer;
|
|
||||||
int c = count;
|
|
||||||
while (c-- > 0)
|
|
||||||
{
|
|
||||||
*d++ = *s++;
|
|
||||||
*d++ = *s++;
|
|
||||||
s++;
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (checksum)
|
|
||||||
crc32 = rb->crc_32(dspbuffer, count * 2 * channels, crc32);
|
|
||||||
else
|
|
||||||
rb->write(wavinfo.fd, dspbuffer, count * 2 * channels);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (wavinfo.sampledepth <= 16) {
|
if (wavinfo.sampledepth <= 16) {
|
||||||
data1_16 = ch1;
|
data1_16 = ch1;
|
||||||
data2_16 = ch2;
|
data2_16 = ch2;
|
||||||
|
@ -378,18 +369,18 @@ static void pcmbuf_insert_wav_checksum(const void *ch1, const void *ch2, int cou
|
||||||
{
|
{
|
||||||
case STEREO_INTERLEAVED:
|
case STEREO_INTERLEAVED:
|
||||||
while (count--) {
|
while (count--) {
|
||||||
int2le16(p, clip_sample((*data1_32++ + dc_bias) >> scale));
|
int2le16(p, clip_sample_16((*data1_32++ + dc_bias) >> scale));
|
||||||
p += 2;
|
p += 2;
|
||||||
int2le16(p, clip_sample((*data1_32++ + dc_bias) >> scale));
|
int2le16(p, clip_sample_16((*data1_32++ + dc_bias) >> scale));
|
||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STEREO_NONINTERLEAVED:
|
case STEREO_NONINTERLEAVED:
|
||||||
while (count--) {
|
while (count--) {
|
||||||
int2le16(p, clip_sample((*data1_32++ + dc_bias) >> scale));
|
int2le16(p, clip_sample_16((*data1_32++ + dc_bias) >> scale));
|
||||||
p += 2;
|
p += 2;
|
||||||
int2le16(p, clip_sample((*data2_32++ + dc_bias) >> scale));
|
int2le16(p, clip_sample_16((*data2_32++ + dc_bias) >> scale));
|
||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +388,7 @@ static void pcmbuf_insert_wav_checksum(const void *ch1, const void *ch2, int cou
|
||||||
|
|
||||||
case STEREO_MONO:
|
case STEREO_MONO:
|
||||||
while (count--) {
|
while (count--) {
|
||||||
int2le16(p, clip_sample((*data1_32++ + dc_bias) >> scale));
|
int2le16(p, clip_sample_16((*data1_32++ + dc_bias) >> scale));
|
||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -514,17 +505,17 @@ static void configure(int setting, intptr_t value)
|
||||||
case DSP_SWITCH_FREQUENCY:
|
case DSP_SWITCH_FREQUENCY:
|
||||||
case DSP_SET_FREQUENCY:
|
case DSP_SET_FREQUENCY:
|
||||||
DEBUGF("samplerate=%d\n",(int)value);
|
DEBUGF("samplerate=%d\n",(int)value);
|
||||||
wavinfo.samplerate = (int)value;
|
wavinfo.samplerate = use_dsp ? NATIVE_FREQUENCY : (int)value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DSP_SET_SAMPLE_DEPTH:
|
case DSP_SET_SAMPLE_DEPTH:
|
||||||
DEBUGF("sampledepth = %d\n",(int)value);
|
DEBUGF("sampledepth = %d\n",(int)value);
|
||||||
wavinfo.sampledepth=(int)value;
|
wavinfo.sampledepth = use_dsp ? 16 : (int)value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DSP_SET_STEREO_MODE:
|
case DSP_SET_STEREO_MODE:
|
||||||
DEBUGF("Stereo mode = %d\n",(int)value);
|
DEBUGF("Stereo mode = %d\n",(int)value);
|
||||||
wavinfo.stereomode=(int)value;
|
wavinfo.stereomode = use_dsp ? STEREO_INTERLEAVED : (int)value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,8 +689,10 @@ static enum plugin_status test_track(const char* filename)
|
||||||
ci.id3 = &track.id3;
|
ci.id3 = &track.id3;
|
||||||
ci.curpos = 0;
|
ci.curpos = 0;
|
||||||
|
|
||||||
if (use_dsp)
|
if (use_dsp) {
|
||||||
rb->dsp_configure(ci.dsp, DSP_RESET, 0);
|
rb->dsp_configure(ci.dsp, DSP_RESET, 0);
|
||||||
|
rb->dsp_configure(ci.dsp, DSP_FLUSH, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (checksum)
|
if (checksum)
|
||||||
crc32 = 0xffffffff;
|
crc32 = 0xffffffff;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue