⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codec_encoder.asm

📁 实现蓝牙 立体声传送
💻 ASM
📖 第 1 页 / 共 2 页
字号:
// *****************************************************************************
// Copyright (C) Cambridge Silicon Radio plc 2003-2006        http://www.csr.com
// Part of BlueLab 3.6.2-release
//
// $Revision$  $Date$
// *****************************************************************************

// *****************************************************************************
// DESCRIPTION
//    Encoder (SBC) for either an audio dongle or a usb dongle
//
// *****************************************************************************

.ifndef SELECTED_CODEC_SBC
   .define SELECTED_CODEC_SBC
.endif

// select the codec specific options
.ifdef SELECTED_CODEC_SBC
   .define SELECTED_CODEC_FRAME_ENCODE_FUNCTION        &$sbcenc.frame_encode
   .define SELECTED_CODEC_RESET_ENCODER_FUNCTION       &$sbcenc.reset_encoder
   .define SELECTED_CODEC_INITIALISE_ENCODER_FUNCTION  $sbcenc.init_encoder
   .define SELECTED_CODEC_LIBRARY_HEADER               "sbc_library.h"
.endif

.ifndef USB_AUDIO_MODE
   // 1.5ms is chosen as the interrupt rate for the audio input/output because:
   // adc/dac mmu buffer is 256byte = 128samples
   //                               - upto 8 sample fifo in voice interface
   //                               = 120samples = 2.5ms @ 48KHz
   // assume obsolute worst case jitter on interrupts = 1ms
   // Hence choose 1.5ms between audio input/output interrupts
   .define TMR_PERIOD_AUDIO_COPY         1500
.endif

// 8ms is chosen as the interrupt rate for the codec input/output as this is a
// good compromise between not overloading the xap with messages and making
// sure that the xap side buffer is emptied relatively often.
.define TMR_PERIOD_CODEC_COPY         8000

// includes
.include "core_library.h"
.include "cbops_library.h"
.include "codec_library.h"
.include SELECTED_CODEC_LIBRARY_HEADER


.MODULE $M.main;
   .CODESEGMENT PM;
   .DATASEGMENT DM;

   $main:

   // ** setup ports that are to be used **
   .ifdef USB_AUDIO_MODE
      .CONST  $USB_IN_PORT            ($cbuffer.READ_PORT_MASK + 0);
   .else
      .CONST  $AUDIO_LEFT_IN_PORT     ($cbuffer.READ_PORT_MASK + 0);
      .CONST  $AUDIO_RIGHT_IN_PORT    ($cbuffer.READ_PORT_MASK + 1);
   .endif
   .CONST  $CODEC_OUT_PORT        ($cbuffer.WRITE_PORT_MASK + 0);


   // ** allocate memory for cbuffers **
   .VAR/DMCIRC $audio_in_left[AUDIO_CBUFFER_SIZE];
   .VAR/DMCIRC $audio_in_right[AUDIO_CBUFFER_SIZE];
   .VAR/DMCIRC $codec_out[CODEC_CBUFFER_SIZE];


   // ** allocate memory for cbuffer structures **
   .VAR $codec_out_cbuffer_struc[$cbuffer.STRUC_SIZE] =
          LENGTH($codec_out),             // size
          &$codec_out,                    // read pointer
          &$codec_out;                    // write pointer
   .VAR $audio_in_left_cbuffer_struc[$cbuffer.STRUC_SIZE] =
          LENGTH($audio_in_left),         // size
          &$audio_in_left,                // read pointer
          &$audio_in_left;                // write pointer
   .VAR $audio_in_right_cbuffer_struc[$cbuffer.STRUC_SIZE] =
          LENGTH($audio_in_right),        // size
          &$audio_in_right,               // read pointer
          &$audio_in_right;               // write pointer


   // ** allocate memory for timer structures **
   .VAR $codec_out_timer_struc[$timer.STRUC_SIZE];
   .VAR $audio_in_timer_struc[$timer.STRUC_SIZE];


   // ** allocate memory for codec cbops copy routine **
   .VAR $codec_out_copy_struc[] =
      &$codec_out_copy_op,                // first operator block
      1,                                  // number of inputs
      &$codec_out_cbuffer_struc,          // input
      1,                                  // number of outputs
      $CODEC_OUT_PORT;                    // output

   .BLOCK $codec_out_copy_op;
      .VAR $codec_out_copy_op.next = $cbops.NO_MORE_OPERATORS;
      .VAR $codec_out_copy_op.func = &$cbops.copy_op;
      .VAR $codec_out_copy_op.param[$cbops.copy_op.STRUC_SIZE] =
               0,                         // Input index
               1;                         // Output index
   .ENDBLOCK;



   .ifdef USB_AUDIO_MODE
      .VAR/DM1 $usb_audio_in_copy_struc[$cbuffer.USB_AUDIO_COPY_STRUC_SIZE] =
               $USB_IN_PORT,
               &$audio_in_left_cbuffer_struc,
               &$audio_in_right_cbuffer_struc,
               $cbuffer.USB_AUDIO_COPY_PACKET_LENGTH_48000HZ_STEREO,
               1024,
               0,
               0,
               0;
   .else
      // ** allocate memory for stereo audio out cbops copy routine **
      .VAR $stereo_audio_in_copy_struc[] =
         &$audio_in_shift_op_left,        // first operator block
         2,                               // number of inputs
         $AUDIO_LEFT_IN_PORT,             // input
         $AUDIO_RIGHT_IN_PORT,            // input
         2,                               // number of outputs
         &$audio_in_left_cbuffer_struc,   // output
         &$audio_in_right_cbuffer_struc;  // output

      .BLOCK $audio_in_shift_op_left;
         .VAR audio_in_shift_op_left.next = &$audio_in_dc_remove_op_left;
         .VAR audio_in_shift_op_left.func = &$cbops.shift;
         .VAR audio_in_shift_op_left.param[$cbops.shift.STRUC_SIZE] =
                  0,                      // Input index (left input port)
                  2,                      // Output index (left cbuffer)
                  8;                      // Shift amount
      .ENDBLOCK;

      .BLOCK $audio_in_dc_remove_op_left;
         .VAR audio_in_dc_remove_op_left.next = &$audio_in_noise_gate_op_left;
         .VAR audio_in_dc_remove_op_left.func = &$cbops.dc_remove;
         .VAR audio_in_dc_remove_op_left.param[$cbops.dc_remove.STRUC_SIZE] =
                  2,                      // Input index (left cbuffer)
                  2;                      // Output index (left cbuffer)
      .ENDBLOCK;

      .BLOCK $audio_in_noise_gate_op_left;
         .VAR audio_in_noise_gate_op_left.next = &$audio_in_shift_op_right;
         .VAR audio_in_noise_gate_op_left.func = &$cbops.noise_gate;
         .VAR audio_in_noise_gate_op_left.param[$cbops.noise_gate.STRUC_SIZE] =
                  2,                      // Input index (left cbuffer)
                  2;                      // Output index (left cbuffer)
      .ENDBLOCK;

      .BLOCK $audio_in_shift_op_right;
         .VAR audio_in_shift_op_right.next = &$audio_in_dc_remove_op_right;
         .VAR audio_in_shift_op_right.func = &$cbops.shift;
         .VAR audio_in_shift_op_right.param[$cbops.shift.STRUC_SIZE] =
                  1,                      // Input index (right input port)
                  3,                      // Output index (right cbuffer)
                  8;                      // Shift amount
      .ENDBLOCK;

      .BLOCK $audio_in_dc_remove_op_right;
         .VAR audio_in_dc_remove_op_right.next = &$audio_in_noise_gate_op_right;
         .VAR audio_in_dc_remove_op_right.func = &$cbops.dc_remove;
         .VAR audio_in_dc_remove_op_right.param[$cbops.dc_remove.STRUC_SIZE] =
                  3,                      // Input index (right cbuffer)
                  3;                      // Output index (right cbuffer)
      .ENDBLOCK;

      .BLOCK $audio_in_noise_gate_op_right;
         .VAR audio_in_noise_gate_op_right.next = $cbops.NO_MORE_OPERATORS;
         .VAR audio_in_noise_gate_op_right.func = &$cbops.noise_gate;
         .VAR audio_in_noise_gate_op_right.param[$cbops.noise_gate.STRUC_SIZE] =
                  3,                      // Input index (right cbuffer)
                  3;                      // Output index (right cbuffer)
      .ENDBLOCK;


      // ** allocate memory for mono audio out cbops copy routine **
      .VAR $mono_audio_in_copy_struc[] =
         &$audio_in_shift_op_mono,
         1,     // number of inputs
         $AUDIO_LEFT_IN_PORT,
         1,     // number of outputs
         &$audio_in_left_cbuffer_struc;

      .BLOCK $audio_in_shift_op_mono;
         .VAR audio_in_shift_op_mono.next = &$audio_in_dc_remove_op_mono;
         .VAR audio_in_shift_op_mono.func = &$cbops.shift;
         .VAR audio_in_shift_op_mono.param[$cbops.shift.STRUC_SIZE] =
                  0,                      // Input index (left input port)
                  1,                      // Output index (left cbuffer)
                  8;                      // Shift amount
      .ENDBLOCK;

      .BLOCK $audio_in_dc_remove_op_mono;
         .VAR audio_in_dc_remove_op_mono.next = &$audio_in_noise_gate_op_mono;
         .VAR audio_in_dc_remove_op_mono.func = &$cbops.dc_remove;
         .VAR audio_in_dc_remove_op_mono.param[$cbops.dc_remove.STRUC_SIZE] =
                  1,                      // Input index (left cbuffer)
                  1;                      // Output index (left cbuffer)
      .ENDBLOCK;

      .BLOCK $audio_in_noise_gate_op_mono;
         .VAR audio_in_noise_gate_op_mono.next = $cbops.NO_MORE_OPERATORS;
         .VAR audio_in_noise_gate_op_mono.func = &$cbops.noise_gate;
         .VAR audio_in_noise_gate_op_mono.param[$cbops.noise_gate.STRUC_SIZE] =
                  1,                      // Input index (left cbuffer)
                  1;                      // Output index (left cbuffer)
      .ENDBLOCK;
   .endif


   // ** allocate memory for codec stream structure **
   .VAR/DM1 $encoder_codec_stream_struc[$codec.stream_encode.STRUC_SIZE] =
            SELECTED_CODEC_FRAME_ENCODE_FUNCTION,     // frame_encode function
            SELECTED_CODEC_RESET_ENCODER_FUNCTION,    // reset_encoder function
            &$codec_out_cbuffer_struc,                // out cbuffer
            &$audio_in_left_cbuffer_struc,            // in left cbuffer
            &$audio_in_right_cbuffer_struc;           // in right cbuffer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -