📄 playsound.c
字号:
#include "typedef.h"
#include "global.h"
#include "msm9841.h"
#include "nf_file.h"
#include "playsound.h"
#include "speakercontrol.h"
#include "menuinterface.h"
#define FULL_BUFFER_SIZE 128
#define MID_BUFFER_SIZE 64
#define SOUND_OFF 0//语音结束(全部读完)
#define SOUND_ON 1//仍然有语音还没有读到缓存中
#define SOUND_STATION 0x7fff//本站
#define SOUNT_LASTSTATION 0x6fff//终点站
extern Uchar volatile xdata D12_Y5;
extern idata Uchar D18CS;//D12_Y5的寄存器
extern xdata BUS_INFO busInfo;//线路当前信息
extern xdata Byte fixedTone[MAX_CUR_FIXNUM];//固定服务短语
extern xdata STATION_TONE stationTone[128];//上下行车站数据
//extern xdata Uint32 tonePointer[MAX_TONEPOINTER_NUMBER];//语音指针
extern xdata Uint16 toneArrayPointer[MAX_TONEARRAY_SIZE];//语音串的存放空间
extern xdata Uint16 toneArrayAddr[MAX_TONEARRAY_NUMBER];//所有语音串的起始序号(在toneArrayPointer中的位置)
xdata PLAY_BUFFER playDir;//播放描述
LITTLESPEAKER_POINTER gLitterSpeaker;
xdata Byte playBuf[128];
bit bPlayFlag;
Byte gPlaySendSize;
/**********报站队列处理************/
PLAY_QUEUE playQueue;
void play_queue_init()
{
playQueue.valid = INVALID_DATA;
}
void del_play_queue()
{
playQueue.valid = INVALID_DATA;
}
void add_play_queue(Byte value)
{
playQueue.valid = VALID_DATA;
playQueue.timeout = PLAY_TIMEOUT;
playQueue.nValue = value;
}
void playqueue_timeout()
{
if (VALID_DATA == playQueue.valid)
{
if (playQueue.timeout > 0)
{
playQueue.timeout--;
if (0 == playQueue.timeout)
{
if (NO_PLAYSOUND == playDir.type)
{
play_notitionsound(playQueue.nValue);
}
del_play_queue();
}
}
else
{
if (NO_PLAYSOUND == playDir.type)
{
play_notitionsound(playQueue.nValue);
}
del_play_queue();
}
}
}
void check_playqueue()
{
if (VALID_DATA == playQueue.valid)
{
play_notitionsound(playQueue.nValue);
del_play_queue();
}
}
void play_init(void)
{
gLitterSpeaker.status = SPEAKER_IDLE;
playDir.type = NO_PLAYSOUND;
IT0 = 1;
EX0 = 1;
play_queue_init();
}
/************播放到/出站信息************/
/*curStation:值从1开始
/********************************/
void play_stationsound(Uint8 curStation/*站点序号*/, Byte attrStation/*到站/出站/首站*/)
{
//stop play previous sound
playDir.type = NO_PLAYSOUND;
playDir.stationVal = curStation;
/*播放对应的串*/
//如果是播放下一站
switch (attrStation)
{
case NEXT_STATION:
if (0 != stationTone[curStation-1].startTone)
{
play_toneArray(stationTone[curStation-1].startTone, STATION_PLAY);
}
else
{
//播放默认
if ((curStation == busInfo.lastStation[0]) || (curStation == busInfo.lastStation[1]))
{
//起步重复语播放
if (0 != fixedTone[3])
{
play_toneArray(fixedTone[3], STATION_PLAY);
}
}
else
{
//默认起步语播放
if (0 != fixedTone[0])
{
play_toneArray(fixedTone[0], STATION_PLAY);
}
}
}
break;
case FIRST_STATION:
{
Byte number;
if (BUS_UPWARD == busInfo.direction)
number = (busInfo.modeNum+2)*2;
else
number = (busInfo.modeNum+2)*2+1;
if (0 != fixedTone[number])
{
play_toneArray(fixedTone[number], STATION_PLAY);
}
else
{
if (0 != fixedTone[2])
{
play_toneArray(fixedTone[2], STATION_PLAY);
}
}
}
break;
case CURRENT_STATION:
if (0 != stationTone[curStation-1].arriveTone)
{
play_toneArray(stationTone[curStation-1].arriveTone, STATION_PLAY);
}
else
{
//播放默认
if ((curStation == busInfo.lastStation[0]) || (curStation == busInfo.lastStation[1]))
{
//终点站重复语播放
if (0 != fixedTone[4])
{
play_toneArray(fixedTone[4], STATION_PLAY);
}
}
else
{
//默认起步语播放
if (0 != fixedTone[1])
{
play_toneArray(fixedTone[1], STATION_PLAY);
}
}
}
break;
default:
break;
}
}
Byte boardMode;
void back_board_mode()
{
D18CS |= 0x02;
D12_Y5 = D18CS;
if (1 == boardMode)
speak_boardcontrol(CONTROL_BOARDOUTER);
else if (2 == boardMode)
speak_boardcontrol(CONTROL_BOARDOUTER|CONTROL_BOARDINNER);
else if (3 == boardMode)
speak_boardcontrol(CONTROL_BOARDINNER);
}
void set_littlespeaker()
{
D18CS &= 0xfd;
D12_Y5 = D18CS;
//设置为内喇叭
speak_boardcontrol(CONTROL_BOARDINNER);
}
void set_board_mode()
{
D18CS |= 0x02;
D12_Y5 = D18CS;
if (toneArrayPointer[playDir.pointVal]> 0xc000)
{
if (2 != boardMode)
{
boardMode = 2;
speak_boardcontrol(CONTROL_BOARDOUTER|CONTROL_BOARDINNER);
}
}
else if (toneArrayPointer[playDir.pointVal]> 0x8000)
{
if (1 != boardMode)
{
boardMode = 1;
speak_boardcontrol(CONTROL_BOARDOUTER);
}
}
else
{
if (0 != boardMode)
{
boardMode = 0;
speak_boardcontrol(CONTROL_BOARDINNER);
}
}
}
Byte littlespeaker_read128()
{
Uint8 nLeft, nTmp, nPos, bFirstRead;
nPos = 0;
nLeft = 128;
bFirstRead = PLAYSOUND_FIRSTREAD;
set_littlespeaker();
while (0 != toneArrayPointer[gLitterSpeaker.pointVal])
{
Uint16 nValue;
nValue = toneArrayPointer[gLitterSpeaker.pointVal]&0x3fff;;
nTmp = nLeft;
//一般的语音段
if (OK == read_filetobuf(gLitterSpeaker.pointVal, gLitterSpeaker.nPosition, playBuf+nPos, &nTmp, bFirstRead))
{
//本段语音读完,此时缓存有可能没有填完
gLitterSpeaker.pointVal++;
gLitterSpeaker.nPosition = 0;
nPos += nTmp;
nLeft -= nTmp;
if (0 == toneArrayPointer[gLitterSpeaker.pointVal])
{
//所有语音都播放完毕
gLitterSpeaker.status = SPEAKER_NOMOREDATA;
break;
}
}
else
{
//本段语音没有读完,但是缓存已经填完
gLitterSpeaker.nPosition += nTmp;
nLeft = 0;
break;
}
bFirstRead = PLAYSOUNT_NEXTREAD;
}
return (128-nLeft);
}
Byte read128_toplaybuf()
{
Uint8 nLeft, nTmp, nPos, bFirstRead;
nPos = 0;
nLeft = 128;
bFirstRead = PLAYSOUND_FIRSTREAD;
set_board_mode();
while (0 != toneArrayPointer[playDir.pointVal])
{
nTmp = nLeft;
if (1 == playDir.valid)
{
Uint16 nValue16;
nValue16 = toneArrayPointer[playDir.pointVal]&0x3fff;
if (0x3fff == nValue16)
{
//本站
if (0 == stationTone[playDir.stationVal-1].stopTone)
{
playDir.pointVal++;
}
else
{
playDir.valid = 2;
playDir.pointVal2 = toneArrayAddr[stationTone[playDir.stationVal-1].stopTone-1];
//直接跳到下一个循环,来读取子串中的语音
}
}
else if (0x2fff == nValue16)
{
if (0 == stationTone[busInfo.lastStation[busInfo.direction]-1].stopTone)
{
playDir.pointVal++;
}
else
{
//终点站
playDir.valid = 2;
playDir.pointVal2 = toneArrayAddr[stationTone[busInfo.lastStation[busInfo.direction]-1].stopTone-1];
//直接跳到下一个循环,来读取子串中的语音
}
}
else if (0x1fff == nValue16)
{
//终点站播报
if ((busInfo.displayCurStation == busInfo.lastStation[0]) || (busInfo.displayCurStation == busInfo.lastStation[1]))
{
//当前为终点站
if (0 != fixedTone[36])
{
playDir.valid = 2;
playDir.pointVal2 = toneArrayAddr[fixedTone[36]-1];
}
else
{
playDir.pointVal++;
}
}
else
{
//当前不为终点站
playDir.pointVal++;
}
//直接跳到下一个循环,来读取子串中的语音
}
else
{
//一般的语音段
if (OK == read_filetobuf(nValue16, playDir.nPosition, playBuf+nPos, &nTmp, bFirstRead))
{
//本段语音读完,此时缓存有可能没有填完
playDir.pointVal++;
playDir.nPosition = 0;
nPos += nTmp;
nLeft -= nTmp;
if (0 == toneArrayPointer[playDir.pointVal])
{
//所有语音都播放完毕
playDir.type = NO_PLAYSOUND;
break;
}
}
else
{
//本段语音没有读完,但是缓存已经填完
playDir.nPosition += nTmp;
nLeft = 0;
break;
}
bFirstRead = PLAYSOUNT_NEXTREAD;
}
}
else
{
if (OK == read_filetobuf(toneArrayPointer[playDir.pointVal2], playDir.nPosition, playBuf+nPos, &nTmp, bFirstRead))
{
//本段语音读完
nPos += nTmp;
nLeft -= nTmp;
playDir.pointVal2++;
playDir.nPosition = 0;
if (0 == toneArrayPointer[playDir.pointVal2])
{
//该子串读完
playDir.valid = 1;
playDir.pointVal++;
if (0 == toneArrayPointer[playDir.pointVal])
{
playDir.type = NO_PLAYSOUND;
break;
}
}
}
else
{
//子串还没有读完,但缓冲区已经填完
playDir.nPosition += nTmp;
nLeft = 0;
break;
}
bFirstRead = PLAYSOUNT_NEXTREAD;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -