File: sound.cpp

package info (click to toggle)
wing 0.7-33
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,744 kB
  • sloc: cpp: 2,526; sh: 65; makefile: 16
file content (83 lines) | stat: -rw-r--r-- 1,792 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "sound.h"

AUDIOSTREAM *stream = NULL;
FILE        *stream_file  = NULL;
WFXSTREAM    wfx;
int 			stream_vol = DEFAULT_STREAM_VOL;
int 			sample_vol = DEFAULT_SAMPLE_VOL;

void stream_callback(void)
{
	if (stream_file && stream)
   {
		unsigned char *p = (unsigned char *)get_audio_stream_buffer(stream);
		if (p)
      {
	      if (feof(stream_file))
         {
				fseek(stream_file, 22, SEEK_SET);
				wfx.played = 0;
			}
 			if (wfx.played >= wfx.len - (STREAM_BUFFER_SIZE * wfx.bps))
        		memset(p, 0x80, STREAM_BUFFER_SIZE * wfx.bps);

	      wfx.played += fread(p, 1, STREAM_BUFFER_SIZE * wfx.bps, stream_file);
	   	free_audio_stream_buffer(stream);
   	}
	}
}
END_OF_FUNCTION(stream_callback);


void install_stream()
{
  LOCK_FUNCTION(stream_callback);
  LOCK_VARIABLE(stream);
  LOCK_VARIABLE(stream_file);
  LOCK_VARIABLE(wfx);
  stream_file  = NULL;
  stream = NULL;
}


void stream_start()
{
  install_int_ex(stream_callback, MSEC_TO_TIMER(250));
}


void stream_select_mfx( char *name )
{
	if (stream)
   {
		stop_audio_stream(stream);
		stream = NULL;
   }
   if (stream_file)
   {
		fclose(stream_file);
		stream_file = NULL;
   }
   stream_file = fopen(name,"rb");
   if (stream_file)
   {
		fgets( wfx.sig, 7, stream_file);
      wfx.len    = _getw(stream_file);
      wfx.bits   = _getw(stream_file);
      wfx.stereo = _getw(stream_file);
      wfx.freq   = _getw(stream_file);
      wfx.bps    = (wfx.bits / 8) * (wfx.stereo ? 2 : 1);
      wfx.played = 0;
      stream = play_audio_stream(STREAM_BUFFER_SIZE, wfx.bits, wfx.stereo, wfx.freq, stream_vol, 128);
	}
}


void stream_stop()
{
//  fclose(stream_file);
//  stream_file = NULL;
//  stop_audio_stream(stream);
}