ソースを参照

AudioPlayMemory using u-law and simpler header

dds
PaulStoffregen 11年前
コミット
c6962f58b4
3個のファイルの変更75行の追加36行の削除
  1. +24
    -35
      Audio.cpp
  2. +1
    -1
      Audio.h
  3. +50
    -0
      ulaw.c

+ 24
- 35
Audio.cpp ファイルの表示

@@ -1536,25 +1536,11 @@ void AudioPlayMemory::play(const unsigned int *data)
uint32_t format;

playing = 0;
length = *data++;
prior = 0;
format = *data++;
next = data;
prior = 0;
if (format == (44100 | (8 << 24))) {
playing = 1;
} else if (format == (44100 | (16 << 24))) {
playing = 2;
} else if (format == (22050 | (8 << 24))) {
playing = 3;
} else if (format == (22050 | (16 << 24))) {
playing = 4;
} else if (format == (11025 | (8 << 24))) {
playing = 5;
} else if (format == (11025 | (16 << 24))) {
playing = 6;
} else if (format == (8000 | (8 << 24))) {
playing = 7;
}
length = format & 0xFFFFFF;
playing = format >> 24;
}

void AudioPlayMemory::stop(void)
@@ -1562,6 +1548,9 @@ void AudioPlayMemory::stop(void)
playing = 0;
}

extern "C" {
extern const int16_t ulaw_decode_table[256];
};

void AudioPlayMemory::update(void)
{
@@ -1583,18 +1572,18 @@ void AudioPlayMemory::update(void)
s0 = prior;

switch (playing) {
case 1: // 8 bits, 44100 Hz - works
case 0x01: // u-law encoded, 44100 Hz
for (i=0; i < AUDIO_BLOCK_SAMPLES; i += 4) {
tmp32 = *in++;
*out++ = (int8_t)(tmp32 & 255) << 8;
*out++ = (int8_t)((tmp32 >> 8) & 255) << 8;
*out++ = (int8_t)((tmp32 >> 16) & 255) << 8;
*out++ = (int8_t)((tmp32 >> 24) & 255) << 8;
*out++ = ulaw_decode_table[(tmp32 >> 0) & 255];
*out++ = ulaw_decode_table[(tmp32 >> 8) & 255];
*out++ = ulaw_decode_table[(tmp32 >> 16) & 255];
*out++ = ulaw_decode_table[(tmp32 >> 24) & 255];
}
consumed = 128;
break;

case 2: // 16 bits, 44100 Hz - ???
case 0x81: // 16 bit PCM, 44100 Hz
for (i=0; i < AUDIO_BLOCK_SAMPLES; i += 2) {
tmp32 = *in++;
*out++ = (int16_t)(tmp32 & 65535);
@@ -1603,13 +1592,13 @@ void AudioPlayMemory::update(void)
consumed = 128;
break;

case 3: // 8 bits, 22050 Hz - works
case 0x02: // u-law encoded, 22050 Hz
for (i=0; i < AUDIO_BLOCK_SAMPLES; i += 8) {
tmp32 = *in++;
s1 = (int8_t)((tmp32 >> 0) & 255) << 8;
s2 = (int8_t)((tmp32 >> 8) & 255) << 8;
s3 = (int8_t)((tmp32 >> 16) & 255) << 8;
s4 = (int8_t)((tmp32 >> 24) & 255) << 8;
s1 = ulaw_decode_table[(tmp32 >> 0) & 255];
s2 = ulaw_decode_table[(tmp32 >> 8) & 255];
s3 = ulaw_decode_table[(tmp32 >> 16) & 255];
s4 = ulaw_decode_table[(tmp32 >> 24) & 255];
*out++ = (s0 + s1) >> 1;
*out++ = s1;
*out++ = (s1 + s2) >> 1;
@@ -1623,7 +1612,7 @@ void AudioPlayMemory::update(void)
consumed = 64;
break;

case 4: // 16 bits, 22050 Hz - ??
case 0x82: // 16 bits PCM, 22050 Hz
for (i=0; i < AUDIO_BLOCK_SAMPLES; i += 4) {
tmp32 = *in++;
s1 = (int16_t)(tmp32 & 65535);
@@ -1637,13 +1626,13 @@ void AudioPlayMemory::update(void)
consumed = 64;
break;

case 5: // 8 bits, 11025 Hz - ??
case 0x03: // u-law encoded, 11025 Hz
for (i=0; i < AUDIO_BLOCK_SAMPLES; i += 16) {
tmp32 = *in++;
s1 = (int8_t)((tmp32 >> 0) & 255) << 8;
s2 = (int8_t)((tmp32 >> 8) & 255) << 8;
s3 = (int8_t)((tmp32 >> 16) & 255) << 8;
s4 = (int8_t)((tmp32 >> 24) & 255) << 8;
s1 = ulaw_decode_table[(tmp32 >> 0) & 255];
s2 = ulaw_decode_table[(tmp32 >> 8) & 255];
s3 = ulaw_decode_table[(tmp32 >> 16) & 255];
s4 = ulaw_decode_table[(tmp32 >> 24) & 255];
*out++ = (s0 * 3 + s1) >> 2;
*out++ = (s0 + s1) >> 1;
*out++ = (s0 + s1 * 3) >> 2;
@@ -1665,7 +1654,7 @@ void AudioPlayMemory::update(void)
consumed = 32;
break;

case 6: // 16 bits, 11025 Hz - ??
case 0x83: // 16 bit PCM, 11025 Hz
for (i=0; i < AUDIO_BLOCK_SAMPLES; i += 8) {
tmp32 = *in++;
s1 = (int16_t)(tmp32 & 65535);

+ 1
- 1
Audio.h ファイルの表示

@@ -277,7 +277,7 @@ private:
const unsigned int *next;
uint32_t length;
int16_t prior;
uint8_t playing;
volatile uint8_t playing;
};



+ 50
- 0
ulaw.c ファイルの表示

@@ -1,5 +1,54 @@
#include <stdint.h>


const int16_t ulaw_decode_table[256] = {
4, 12, 20, 28, 36, 44, 52, 60, 68, 76,
84, 92, 100, 108, 116, 124, 136, 152, 168, 184,
200, 216, 232, 248, 264, 280, 296, 312, 328, 344,
360, 376, 400, 432, 464, 496, 528, 560, 592, 624,
656, 688, 720, 752, 784, 816, 848, 880, 928, 992,
1056, 1120, 1184, 1248, 1312, 1376, 1440, 1504, 1568, 1632,
1696, 1760, 1824, 1888, 1984, 2112, 2240, 2368, 2496, 2624,
2752, 2880, 3008, 3136, 3264, 3392, 3520, 3648, 3776, 3904,
4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400,
6656, 6912, 7168, 7424, 7680, 7936, 8320, 8832, 9344, 9856,
10368, 10880, 11392, 11904, 12416, 12928, 13440, 13952, 14464, 14976,
15488, 16000, 16768, 17792, 18816, 19840, 20864, 21888, 22912, 23936,
24960, 25984, 27008, 28032, 29056, 30080, 31104, 32128, -4, -12,
-20, -28, -36, -44, -52, -60, -68, -76, -84, -92,
-100, -108, -116, -124, -136, -152, -168, -184, -200, -216,
-232, -248, -264, -280, -296, -312, -328, -344, -360, -376,
-400, -432, -464, -496, -528, -560, -592, -624, -656, -688,
-720, -752, -784, -816, -848, -880, -928, -992, -1056, -1120,
-1184, -1248, -1312, -1376, -1440, -1504, -1568, -1632, -1696, -1760,
-1824, -1888, -1984, -2112, -2240, -2368, -2496, -2624, -2752, -2880,
-3008, -3136, -3264, -3392, -3520, -3648, -3776, -3904, -4096, -4352,
-4608, -4864, -5120, -5376, -5632, -5888, -6144, -6400, -6656, -6912,
-7168, -7424, -7680, -7936, -8320, -8832, -9344, -9856,-10368,-10880,
-11392,-11904,-12416,-12928,-13440,-13952,-14464,-14976,-15488,-16000,
-16768,-17792,-18816,-19840,-20864,-21888,-22912,-23936,-24960,-25984,
-27008,-28032,-29056,-30080,-31104,-32128
};
/*
#! /usr/bin/perl
print "const int16_t ulaw_decode_table[256] = {\n";
for ($i=0; $i < 256; $i++) {
$r = ($i >> 4) & 7;
$n = ($i & 0xF) << ($r + 3);
$n |= 1 << ($r + 7);
$n |= 1 << ($r + 2);
$n -= 128;
$n *= -1 if $i > 127;
printf "%6d", $n + 0;
print "," if ($i < 255);
print "\n" if ($i % 10) == 9;
}
print "\n};\n";
*/



/*
const int16_t ulaw_decode_table[256] = {
0, 8, 16, 24, 32, 40, 48, 56, 64, 72,
80, 88, 96, 104, 112, 120, 128, 144, 160, 176,
@@ -28,6 +77,7 @@ const int16_t ulaw_decode_table[256] = {
-16256,-17280,-18304,-19328,-20352,-21376,-22400,-23424,-24448,-25472,
-26496,-27520,-28544,-29568,-30592,-31616
};
*/
/*
#! /usr/bin/perl
print "const int16_t ulaw_decode_table[256] = {\n";

読み込み中…
キャンセル
保存