@@ -92,11 +92,11 @@ function linear_decay(decay_period: number): (t: number) => number {
9292 * Determine if the user has already provided permission to use the
9393 * microphone and return the provided MediaStream if they have.
9494 */
95- function check_permission ( ) {
95+ function getAudioStream ( func_name : string ) {
9696 if ( globalVars . stream === null ) {
97- throw new Error ( ' Call init_record(); to obtain permission to use microphone' ) ;
97+ throw new Error ( ` ${ func_name } : Call init_record(); to obtain permission to use microphone` ) ;
9898 } else if ( globalVars . stream === false ) {
99- throw new Error ( `Permission has been denied.\n
99+ throw new Error ( `${ func_name } : Permission has been denied.\n
100100 Re-start browser and call init_record();\n
101101 to obtain permission to use microphone.` ) ;
102102 }
@@ -201,7 +201,7 @@ export function record(buffer: number): () => SoundPromise {
201201 throw new Error ( `${ record . name } : Cannot record while another sound is playing!` ) ;
202202 }
203203
204- const stream = check_permission ( ) ;
204+ const stream = getAudioStream ( record . name ) ;
205205 const mediaRecorder = new MediaRecorder ( stream ) ;
206206
207207 setTimeout ( ( ) => {
@@ -254,7 +254,7 @@ export function record_for(duration: number, buffer: number): SoundPromise {
254254 throw new Error ( `${ record_for . name } : Cannot record while another sound is playing!` ) ;
255255 }
256256
257- const stream = check_permission ( ) ;
257+ const stream = getAudioStream ( record_for . name ) ;
258258 const mediaRecorder = new MediaRecorder ( stream ) ;
259259
260260 // order of events for record_for:
@@ -380,8 +380,7 @@ export function play_wave(wave: Wave, duration: number): Sound {
380380}
381381
382382/**
383- * Plays the given Sound using the computer’s sound device.
384- * The sound is added to a list of sounds to be played one-at-a-time
383+ * Adds the given Sound to a list of sounds to be played one-at-a-time
385384 * in a Source Academy tab.
386385 *
387386 * @param sound the Sound to play
@@ -392,7 +391,6 @@ export function play_in_tab(sound: Sound): Sound {
392391 // Type-check sound
393392 if ( ! is_sound ( sound ) ) {
394393 throw new Error ( `${ play_in_tab . name } is expecting sound, but encountered ${ sound } ` ) ;
395- // If a sound is already playing, terminate execution.
396394 }
397395
398396 const duration = get_duration ( sound ) ;
0 commit comments