📄 codec_encoder.asm
字号:
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
.VAR $codec_reset_needed;
// initialise the stack library
call $stack.initialise;
// initialise the interrupt library
call $interrupt.initialise;
// initialise the message library
call $message.initialise;
// initialise the cbuffer library
call $cbuffer.initialise;
.ifdef DEBUG_ON
// initialise the profiler library
call $profiler.initialise;
.endif
// initialise the codec encoder library
call SELECTED_CODEC_INITIALISE_ENCODER_FUNCTION;
// tell vm we're ready and wait for the go message
call $message.send_ready_wait_for_go;
.ifdef USB_AUDIO_MODE
// start timer that copies input samples
r1 = &$audio_in_timer_struc;
r2 = $cbuffer.USB_AUDIO_COPY_NORMAL_TIMER_PERIOD;
r3 = &$usb_audio_in_copy_handler;
call $timer.schedule_event_in;
.else
// left and right audio channels from the mmu have been synced to each other
// by the vm app but are free running in that the dsp doesn't tell them to
// start. We need to make sure that our copying between the cbuffers and
// the mmu buffers starts off in sync with respect to left and right
// channels. To do this we make sure that when we start the copying timers
// that there is no chance of a buffer wrap around occuring within the timer
// period. The easiest way to do this is to start the timers just after a
// buffer wrap around occurs.
// wait for ADC buffers to have just wrapped around
wait_for_adc_buffer_wraparound:
r0 = $AUDIO_LEFT_IN_PORT;
call $cbuffer.calc_amount_data;
// if the amount of data in the buffer is less than 16 samples then a
// buffer wrap around must have just ocurred.
Null = r0 - 16;
if POS jump wait_for_adc_buffer_wraparound;
// start timer that copies input samples
r1 = &$audio_in_timer_struc;
r2 = TMR_PERIOD_AUDIO_COPY;
r3 = &$audio_in_copy_handler;
call $timer.schedule_event_in;
.endif
// start timer that copies codec output data
r1 = &$codec_out_timer_struc;
r2 = TMR_PERIOD_CODEC_COPY;
r3 = &$codec_out_copy_handler;
call $timer.schedule_event_in;
// continually encode codec frames
frame_loop:
Null = M[$codec_reset_needed];
if Z jump no_codec_reset;
r5 = &$encoder_codec_stream_struc;
r0 = M[r5 + $codec.stream_encode.RESET_ADDR_FIELD];
call r0;
M[$codec_reset_needed] = 0;
no_codec_reset:
// encode a frame
r5 = &$encoder_codec_stream_struc;
call $codec.stream_encode;
Null = r0 - $codec.STREAM_CAN_IDLE;
if Z call $timer.1ms_delay;
jump frame_loop;
.ENDMODULE;
.ifdef USB_AUDIO_MODE
// *****************************************************************************
// MODULE:
// $usb_audio_in_copy_handler
//
// DESCRIPTION:
// Function to copy the samples from the USB port on a timer
// interrupt
//
// *****************************************************************************
.MODULE $M.usb_audio_in_copy_handler;
.CODESEGMENT PM;
.DATASEGMENT DM;
$usb_audio_in_copy_handler:
// push rLink onto stack
$push_rLink_macro;
// copy data from the usb port to the left and right cbuffers
r8 = &$usb_audio_in_copy_struc;
call $cbuffer.usb_audio_copy;
// reset codec if usb data has stopped
Null = r0 - $cbuffer.USB_AUDIO_COPY_CODEC_RESET_NEEDED;
if NZ jump no_codec_reset;
r1 = 1;
M[$codec_reset_needed] = r1;
no_codec_reset:
// post another timer event (usb_audio_copy has set the time required - r2)
r1 = &$audio_in_timer_struc;
r3 = &$usb_audio_in_copy_handler;
call $timer.schedule_event_in_period;
// pop rLink from stack
jump $pop_rLink_and_rts;
.ENDMODULE;
.else
// *****************************************************************************
// MODULE:
// $audio_in_copy_handler
//
// DESCRIPTION:
// Function to copy the input samples from the input port(s) to cbuffer(s)
// on a timer interrupt.
//
// *****************************************************************************
.MODULE $M.audio_in_copy_handler;
.CODESEGMENT PM;
.DATASEGMENT DM;
$audio_in_copy_handler:
// push rLink onto stack
$push_rLink_macro;
// copy audio data from the port to the cbuffer
// (selecting either mono or stereo)
r8 = &$stereo_audio_in_copy_struc;
r7 = &$mono_audio_in_copy_struc;
r0 = $AUDIO_RIGHT_IN_PORT;
call $cbuffer.is_it_enabled;
if Z r8 = r7;
// Copy data from the port(s) to the cbuffer(s)
call $cbops.copy;
// post another timer event
r1 = &$audio_in_timer_struc;
r2 = TMR_PERIOD_AUDIO_COPY;
r3 = &$audio_in_copy_handler;
call $timer.schedule_event_in_period;
// pop rLink from stack
jump $pop_rLink_and_rts;
.ENDMODULE;
.endif
// *****************************************************************************
// MODULE:
// $codec_out_copy_handler
//
// DESCRIPTION:
// Function to copy the encoded samples to the output port on a timer
// interrupt.
//
// *****************************************************************************
.MODULE $M.codec_out_copy_handler;
.CODESEGMENT PM;
.DATASEGMENT DM;
$codec_out_copy_handler:
// push rLink onto stack
$push_rLink_macro;
// copy data from cbuffer to the port
r8 = &$codec_out_copy_struc;
call $cbops.copy;
// post another timer event
r1 = &$codec_out_timer_struc;
r2 = TMR_PERIOD_CODEC_COPY;
r3 = &$codec_out_copy_handler;
call $timer.schedule_event_in;
// pop rLink from stack
jump $pop_rLink_and_rts;
.ENDMODULE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -