Skip to content

Commit d8d1b6c

Browse files
author
Ulrich Hecht
committed
basic: move sound code to basic_sound.cpp
1 parent 084ed20 commit d8d1b6c

4 files changed

Lines changed: 212 additions & 199 deletions

File tree

ttbasic/basic.cpp

Lines changed: 0 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,9 +2063,6 @@ void itroff() {
20632063
trace_enabled = false;
20642064
}
20652065

2066-
bool event_play_enabled;
2067-
uint8_t event_play_proc_idx[SOUND_CHANNELS];
2068-
20692066
#define MAX_PADS 3
20702067
bool event_pad_enabled;
20712068
uint8_t event_pad_proc_idx[MAX_PADS];
@@ -2929,16 +2926,6 @@ void BASIC_FP do_call(uint8_t proc_idx)
29292926
return;
29302927
}
29312928

2932-
void BASIC_INT event_handle_play(int ch)
2933-
{
2934-
if (event_play_proc_idx[ch] == NO_PROC)
2935-
return;
2936-
init_stack_frame();
2937-
push_num_arg(ch);
2938-
do_call(event_play_proc_idx[ch]);
2939-
event_play_enabled = false;
2940-
}
2941-
29422929
#define EVENT_PROFILE_SAMPLES 7
29432930
uint32_t event_profile[EVENT_PROFILE_SAMPLES];
29442931

@@ -3692,141 +3679,6 @@ void SMALL ismode() {
36923679
flags);
36933680
}
36943681

3695-
/***bc snd BEEP
3696-
Produces a sound using the "beeper" sound engine.
3697-
\usage BEEP period[, volume]
3698-
\args
3699-
@period - tone cycle period in samples [`0` (off) to `320`/`160`]
3700-
@volume - tone volume +
3701-
[`0` to `15`, default: as set in system configuration]
3702-
\note
3703-
The maximum value for `period` depends on the flavor of Engine BASIC;
3704-
it's 320 for the gaming build, and 160 for the network build.
3705-
\ref CONFIG
3706-
***/
3707-
void ibeep() {
3708-
int32_t period;
3709-
int32_t vol = CONFIG.beep_volume;
3710-
3711-
if ( getParam(period, 0, SOUND_BUFLEN, I_NONE) ) return;
3712-
if(*cip == I_COMMA) {
3713-
cip++;
3714-
if ( getParam(vol, 0, 15, I_NONE) ) return;
3715-
}
3716-
if (period == 0)
3717-
sound.noBeep();
3718-
else
3719-
sound.beep(period, vol);
3720-
}
3721-
3722-
/***bc snd SOUND FONT
3723-
Sets the sound font to be used by the wavetable synthesizer.
3724-
\usage SOUND FONT file$
3725-
\args
3726-
@file$ name of the SF2 sound font file
3727-
\note
3728-
If a relative path is specified, Engine BASIC will first attempt
3729-
to load the sound font from `/sd`, then from `/flash`.
3730-
3731-
The default sound font name is `1mgm.sf2`.
3732-
\bugs
3733-
No sanity checks are performed before setting the sound font.
3734-
\ref INST$()
3735-
***/
3736-
3737-
/***bc snd SOUND
3738-
Generates a sound using the wavetable synthesizer.
3739-
\usage SOUND ch, inst, note[, len[, vel]]
3740-
\args
3741-
@ch sound channel [`0` to `{SOUND_CHANNELS_m1}`]
3742-
@inst instrument number
3743-
@note note pitch
3744-
@len note duration, milliseconds [default: 1000]
3745-
@vel note velocity [`0` to `1` (default)]
3746-
\ref INST$() SOUND_FONT
3747-
***/
3748-
void isound() {
3749-
#ifdef HAVE_TSF
3750-
if (*cip == I_FONT) {
3751-
++cip;
3752-
BString font = getParamFname();
3753-
sound.setFontName(font);
3754-
} else {
3755-
int32_t ch, inst, note, len = 1000;
3756-
num_t vel = 1;
3757-
if (getParam(ch, 0, SOUND_CHANNELS - 1, I_COMMA)) return;
3758-
int instcnt = sound.instCount();
3759-
if (!instcnt) {
3760-
err = ERR_TSF;
3761-
return;
3762-
}
3763-
if (getParam(inst, 0, instcnt - 1, I_COMMA)) return;
3764-
if (getParam(note, 0, INT32_MAX, I_NONE)) return;
3765-
if (*cip == I_COMMA) {
3766-
++cip;
3767-
if (getParam(len, 0, INT32_MAX, I_NONE)) return;
3768-
if (*cip == I_COMMA) {
3769-
++cip;
3770-
if (getParam(vel, 0, 1.0, I_NONE)) return;
3771-
}
3772-
}
3773-
sound.noteOn(ch, inst, note, vel, len);
3774-
}
3775-
#else
3776-
err = ERR_NOT_SUPPORTED;
3777-
#endif
3778-
}
3779-
3780-
#ifdef HAVE_MML
3781-
BString mml_text;
3782-
#endif
3783-
/***bc snd PLAY
3784-
Plays a piece of music in Music Macro Language (MML) using the
3785-
wavetable synthesizer.
3786-
\usage PLAY mml$
3787-
\args
3788-
@mml$ score in MML format
3789-
\bugs
3790-
* Only supports one sound channel.
3791-
* MML syntax undocumented.
3792-
* Fails silently if the synthesizer could not be initialized.
3793-
***/
3794-
void iplay() {
3795-
#ifdef HAVE_MML
3796-
sound.stopMml(0);
3797-
mml_text = istrexp();
3798-
sound.playMml(0, mml_text.c_str());
3799-
#else
3800-
err = ERR_NOT_SUPPORTED;
3801-
#endif
3802-
}
3803-
3804-
/***bc snd SAY
3805-
Speaks the given text.
3806-
\usage SAY text$
3807-
\args
3808-
@text$ text to be spoken
3809-
\note
3810-
`text$` is assumed to be in English.
3811-
3812-
`SAY` cannot be used concurrently with the wavetable synthesizer
3813-
because they use different sample rates.
3814-
\bugs
3815-
* Does not support phonetic input.
3816-
* No possibility to change synthesizer parameters.
3817-
***/
3818-
void isay() {
3819-
BString text = istrexp();
3820-
if (err)
3821-
return;
3822-
ESP8266SAM *sam = sound.sam();
3823-
if (!sam) {
3824-
err = ERR_OOM;
3825-
return;
3826-
}
3827-
sam->Say(text.c_str());
3828-
}
3829-
38303682
/***bf bas MAP
38313683
Re-maps a value from one range to another
38323684
\usage mval = MAP(val, l1, h1, l2, h2)
@@ -4738,27 +4590,6 @@ static BString BASIC_INT sinkey() {
47384590
return BString();
47394591
}
47404592

4741-
/***bf snd INST$
4742-
Returns the name of the specified wavetable synthesizer instrument.
4743-
\usage name$ = INST$(num)
4744-
\args
4745-
@num instrument number
4746-
\ret
4747-
Instrument name.
4748-
4749-
If an instrument is not defined in the current sound font, an empty
4750-
string is returned.
4751-
\ref SOUND_FONT
4752-
***/
4753-
static BString sinst() {
4754-
#ifdef HAVE_TSF
4755-
return sound.instName(getparam());
4756-
#else
4757-
err = ERR_NOT_SUPPORTED;
4758-
return BString();
4759-
#endif
4760-
}
4761-
47624593
/***bf bas RET$
47634594
Returns one of the string return values returned by the last function
47644595
call.
@@ -5139,34 +4970,6 @@ num_t BASIC_FP nleft() {
51394970
return psxLeft;
51404971
}
51414972

5142-
/***bf snd PLAY
5143-
Checks if a sound is playing a on wavetable synthesizer channel.
5144-
\usage p = PLAY(channel)
5145-
\args
5146-
@channel sound channel +
5147-
[`0` to `{SOUND_CHANNELS_m1}`, or `-1` to check all channels]
5148-
\ret `1` if sound is playing, `0` otherwise.
5149-
\ref PLAY SOUND
5150-
***/
5151-
num_t BASIC_FP nplay() {
5152-
#ifdef HAVE_MML
5153-
int32_t a, b;
5154-
if (checkOpen()) return 0;
5155-
if (getParam(a, -1, SOUND_CHANNELS - 1, I_CLOSE)) return 0;
5156-
if (a == -1) {
5157-
b = 0;
5158-
for (int i = 0; i < SOUND_CHANNELS; ++i) {
5159-
b |= sound.isPlaying(i);
5160-
}
5161-
return b;
5162-
} else
5163-
return sound.isPlaying(a);
5164-
#else
5165-
err = ERR_NOT_SUPPORTED;
5166-
return 0;
5167-
#endif
5168-
}
5169-
51704973
#ifndef ESP8266
51714974
int try_malloc() {
51724975
uint32_t total = 0;

ttbasic/basic.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "video.h"
1313
#include "variable.h"
1414
#include "proc.h"
15+
#include "sound.h"
1516

1617
#define SIZE_LINE 256 // コマンドライン入力バッファサイズ + NULL
1718
#define SIZE_IBUF 256 // 中間コード変換バッファサイズ
@@ -372,6 +373,7 @@ void iloadbg();
372373

373374
int32_t ncharfun();
374375
num_t nvreg();
376+
num_t nplay();
375377

376378
#define COL_BG 0
377379
#define COL_FG 1
@@ -405,9 +407,12 @@ extern SystemConfig CONFIG;
405407
#define COL(n) (csp.colorFromRgb(CONFIG.color_scheme[COL_ ## n]))
406408

407409
void BASIC_INT event_handle_play(int ch);
410+
extern bool event_play_enabled;
411+
extern uint8_t event_play_proc_idx[SOUND_CHANNELS];
412+
408413
void event_handle_pad();
409-
void event_handle_sprite();
410414

415+
void event_handle_sprite();
411416
extern uint8_t event_sprite_proc_idx;
412417

413418
#ifdef USE_BG_ENGINE

0 commit comments

Comments
 (0)