Better sound. Buzzing tone was caused by signed/unsigned mixture.
authorRick van Rein <vanrein@hwdev.(none)>
Mon, 12 Dec 2011 10:45:33 +0000 (10:45 +0000)
committerRick van Rein <vanrein@hwdev.(none)>
Mon, 12 Dec 2011 10:45:33 +0000 (10:45 +0000)
Small sounds around 0 became extreme high/low values, so loud/hifreq sound.
Still no mic->buf->spk path, but at 8 kHz noise is now also low.

src/driver/tic55x/grandstream-bt20x.c
src/driver/tlv320aic2x.c
src/function/develtest/echo.c

index 7249410..c01e4a6 100644 (file)
@@ -264,7 +264,7 @@ extern volatile uint16_t threshold_record;
 
 /* Copy encoded samples to plain samples */
 //TODO// Better to switch once and then loop in a separate routine which may even be .asm -- but that could require a codec-specific state storage structure
-int16_t codec_decode (codec_t codec, uint8_t *in, uint16_t inlen, uint16_t *out, uint16_t outlen) {
+int16_t codec_decode (codec_t codec, uint8_t *in, uint16_t inlen, int16_t *out, uint16_t outlen) {
        while ((inlen > 0) && (outlen > 0)) {
                register uint16_t outval;
                register uint8_t inval = *in++;
@@ -309,8 +309,8 @@ int16_t codec_decode (codec_t codec, uint8_t *in, uint16_t inlen, uint16_t *out,
 
 /* Copy plain samples to encoded samples */
 //TODO// Better to switch once and then loop in a separate routine which may even be .asm -- but that could require a codec-specific state storage structure
-int16_t codec_encode (codec_t codec, uint16_t *in, uint16_t inlen, uint8_t *out, uint16_t outlen) {
-bottom_printf ("Have %d, %d, %d at %04x\n", (intptr_t) in [0], (intptr_t) in [1], (intptr_t) in [2], (intptr_t) in);
+int16_t codec_encode (codec_t codec, int16_t *in, uint16_t inlen, uint8_t *out, uint16_t outlen) {
+bottom_printf ("Have %d, %d, %d at %04x\n", (intptr_t) in [0] & 0x0000ffff, (intptr_t) in [1] & 0x0000ffff, (intptr_t) in [2] & 0x0000ffff, (intptr_t) in);
        while ((inlen > 0) && (outlen > 0)) {
                register uint16_t inval = *in++;
                bool signbit;
index fc1634d..de40f48 100644 (file)
@@ -87,8 +87,8 @@ static uint8_t volume [2];
 
 #define BUFSZ (64*25)
 
-volatile uint16_t samplebuf_play   [BUFSZ];
-volatile uint16_t samplebuf_record [BUFSZ];
+volatile int16_t samplebuf_play   [BUFSZ];
+volatile int16_t samplebuf_record [BUFSZ];
 
 volatile uint16_t available_play   = 0;
 volatile uint16_t available_record = 0;
@@ -180,8 +180,8 @@ void bottom_soundchannel_setvolume (uint8_t chan, uint8_t vol) {
 /******** Calls to play or record through a codec ********/
 
 
-int16_t codec_decode (codec_t codec, uint8_t *in, uint16_t inlen, uint16_t *out, uint16_t outlen);
-int16_t codec_encode (codec_t codec, uint16_t *in, uint16_t inlen, uint8_t *out, uint16_t outlen);
+int16_t codec_decode (codec_t codec, uint8_t *in, uint16_t inlen, int16_t *out, uint16_t outlen);
+int16_t codec_encode (codec_t codec, int16_t *in, uint16_t inlen, uint8_t *out, uint16_t outlen);
 void tlv320aic2x_set_samplerate (uint8_t chan, uint32_t samplerate);
 
 
@@ -207,7 +207,7 @@ int16_t bottom_codec_play   (uint8_t chan, codec_t codec, uint8_t *coded_samples
        //TODO// Guard against buffer wraparound
        retval = codec_decode (codec,
                                coded_samples, coded_bytes,
-                               (uint16_t *) (samplebuf_play + nextwrite_play), samples);
+                               (int16_t *) (samplebuf_play + nextwrite_play), samples);
        nextwrite_play += samples;
        available_play += samples;
        if (retval < 0) {
@@ -229,7 +229,7 @@ int16_t bottom_codec_record (uint8_t chan, codec_t codec, uint8_t *coded_samples
                samples = ar;
        }
        retval = codec_encode (codec,
-                               (uint16_t *) (samplebuf_record + nextread_record), samples,
+                               (int16_t *) (samplebuf_record + nextread_record), samples,
                                coded_samples, coded_bytes);
        nextread_record += samples;
        available_record -= samples;
index 6c1229c..5aa199f 100644 (file)
@@ -223,9 +223,8 @@ uint16_t oldspcr1 = 0xffff;
 uint16_t loop = 0;
        bottom_critical_region_end ();
        top_hook_update (bottom_phone_is_offhook ());
-       memset (samples, 0 + 128, sizeof (samples));
-       bottom_codec_play_samplerate (PHONE_CHANNEL_TELEPHONY, 1000);
-       bottom_codec_record_samplerate (PHONE_CHANNEL_TELEPHONY, 1000);
+       bottom_codec_play_samplerate (PHONE_CHANNEL_TELEPHONY, 8000);
+       bottom_codec_record_samplerate (PHONE_CHANNEL_TELEPHONY, 8000);
        bottom_soundchannel_setvolume (PHONE_CHANNEL_TELEPHONY, 127);
        bottom_show_fixed_msg (APP_LEVEL_ZERO, FIXMSG_READY);
        bottom_printf ("Running the development function \"echo\" (Test sound)\n");