📄 main.c
字号:
//============================================================================
//
// The information contained herein is the exclusive property of
// Sunplus Technology Co. And shall not be distributed, reproduced,
// or disclosed in whole in part without prior written permission.
//
// (C) COPYRIGHT 2001 SUNPLUS TECHNOLOGY CO.
// ALL RIGHTS RESERVED
//
// The entire notice above must be reproduced on all authorized copies.
//
//============================================================================
// 工程名称: 语音播放
// 功能描述: 程序4.3 A2000的中断服务程序;SACM-A2000可以完成播放、停止、暂
// 停、继续播放、音量增加、音量减少的功能
// 文件来源: 《SPCE061单片机原理及应用技术》 第四章 程序设计
// IDE环境: SUNPLUS u'nSPTM IDE 1.8.0(or later)
//
// 涉及的库: (a) C-Lib: (CMacro.lib);
// 函数介绍:
// System_Initial(); For Hardware, Keyboard scan, see hardware.asm in detail
// System_ServiceLoop(); For Keyboard scan, see key.asm in detail
// int SP_GetCh();
// Return values of SP_GetCh() : {0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}
// SACM_A2000_Play(Speech index, Channel, Ramp_Set)
// Speech index: 0 - max index
// Channel: 1: DAC1 on
// 2: DAC2 on
// 3: DAC1,2 on
// Ramp_Set 0: Disable both Ramp Up/Dn
// 1: Enable Ramp Up only
// 2: Enable Ramp Dn only
// 3: Enable both Ramp Up/Dn
// SACM_A2000_Stop();
// SACM_A2000_Pause();
// SACM_A2000_Resume();
// SACM_A2000_Volume(volume index);
// volume index: {0..15}
// SACM_A2000_Status();
// bit.0 = 0: speech end
// 1: speech playing
// SACM_A2000_InitDecoder();
// SACM_A2000_FillQueue();
// SACM_A2000_TestQueue();
// SACM_A2000_Decoder();
// 日期: 2003-5-22(建立)
// 2003-7-16(添加版本说明及版权声明并做代码标准化)
// 2005-10-27 (更新库SACMV26e.lib)
//============================================================================
#include "hardware.h"
#define Disable 0
#define Enable 1
#define MaxSpeechNum 1 // Max. of speech in resource
#define MaxVolume 15 // Max. of volume
#define Manual 0
#define Auto 1
int Ret = 0; // Define for return value of subroutine
extern unsigned long RES_A32_SA, RES_A32_EA;
long Addr;
int main(){
int Key = 0; // define for store temperary key code
int SpeechIndex = 0; // Initial to first speech
int VolumeIndex = 7; // Initial to middle volume
int Mode;
Mode = Auto;
//Mode = Manual;
if(Mode == Auto){ // Main loop in c language domain
Ret = System_Initial();
Ret = SACM_A2000_Initial(Auto);
SACM_A2000_Play(SpeechIndex,DAC1+DAC2,Ramp_UpDn_On); // Play speech
while(1){
Key = SP_GetCh();
switch(Key){
case 0x00:
break;
case 0x01:
SACM_A2000_Play(SpeechIndex,DAC1+DAC2, Ramp_UpDn_On); // Play speech
break;
case 0x02:
SACM_A2000_Stop(); // Stop speech
break;
case 0x04:
SACM_A2000_Pause(); // Pause speech
break;
case 0x08:
SACM_A2000_Resume(); // Rusume speech after speech was paused
break;
case 0x10:
VolumeIndex++;
if(VolumeIndex > MaxVolume)
VolumeIndex = MaxVolume;
SACM_A2000_Volume(VolumeIndex); // Speech volume up
break;
case 0x20:
if(VolumeIndex == 0)
VolumeIndex = 0;
else
VolumeIndex--;
SACM_A2000_Volume(VolumeIndex); // Speech volume down
break;
case 0x40:
SpeechIndex++; // Next speech
if(SpeechIndex == MaxSpeechNum)
SpeechIndex = 0;
SACM_A2000_Play(SpeechIndex,DAC1+DAC2, Ramp_UpDn_On);
break;
case 0x80:
if(SpeechIndex == 0) // previous speech
SpeechIndex = MaxSpeechNum;
SpeechIndex--;
SACM_A2000_Play(SpeechIndex,DAC1+DAC2, Ramp_UpDn_On);
break;
default:
break;
}
System_ServiceLoop(); // Service loop for Key Scanning
SACM_A2000_ServiceLoop(); // Service loop for SACM2000 playing
} // while(1)
} // if(Mode == Auto)
if(Mode == Manual){
Addr = RES_A32_SA; // long type address
Ret = System_Initial();
SACM_A2000_Initial(Manual);
SP_RampDnDAC1();
SP_RampDnDAC2();
SACM_A2000_InitDecoder(DAC1);
while(SACM_A2000_TestQueue() != Full)
{ // Fill Queue if not full
Ret = SP_GetResource(Addr);
SACM_A2000_FillQueue(Ret);
Addr++; //
}
while(1)
{
if(SACM_A2000_TestQueue() != Full)
{
Ret = SP_GetResource(Addr);
SACM_A2000_FillQueue(Ret);
Addr++;
}
if(Addr < RES_A32_EA)
SACM_A2000_Decoder(); // Play speech
else
{
SACM_A2000_Stop();
//while(1){}
SP_RampDnDAC1();
SP_RampDnDAC2();
Addr = RES_A32_SA; // long type address
SACM_A2000_InitDecoder(DAC2);
while(SACM_A2000_TestQueue() != Full)
{ // Fill Queue if not full
Ret = SP_GetResource(Addr);
SACM_A2000_FillQueue(Ret);
Addr++; //
}
}
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -