source: golgotha/src/i4/music/stream.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.8 KB
RevLine 
[80]1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef I4_STREAM_MUSIC_HH
10#define I4_STREAM_MUSIC_HH
11
12#include "arch.hh"
13#include "sound/sound.hh"
14
15class i4_voice_class;
16class i4_file_class;
17
18// This class should work on all system that support async read's though
19// The console versions will probably need a different music system because
20// their only disk access is cdrom and that is needed for texture grabbing
21
22class i4_stream_wav_player
23{
24  i4_voice_class *voice;
25
26  void *locked_buffer_start; // used by lock
27  w32   locked_buffer_size;  // used by lock
28
29  void *unused1;
30  w32   unused2;
31
32  enum { FIRST_HALF, SECOND_HALF } last_read;
33 
34  volatile i4_bool wait_read;  // if an async_read has not completed yet
35 
36  i4_file_class *fp;  // file we are reading wav from
37 
38  w32 buf_size, start_file_offset, prev_total, finish_pos;
39 
40  w32 total_size;
41  w32 total_read;
42
43  i4_bool first_time, loop, fits_in_memory, file_finished;
44 
45  // loads more data from disk or clears the buffer
46  void load_buffer(i4_bool async=i4_T);
47
48public:
49
50  // - fp should remain open and will be closed by stream_wav's destructor
51  // - buffer_size is the size of the sound buffer to keep in memory, half the
52  //   sound buffer we be loaded in over time
53  // - if loop is false, wav will play 0's ater song is over
54  // - if you need to sync the start of the sound you should specifiy first_load_is_async
55  //   is false in which case the program will block until first section of sample is loaded
56  i4_voice_class *i4_voice() { return voice; }
57
58  i4_stream_wav_player(i4_file_class *fp,
59                       w32 buffer_size,
60                       i4_bool loop,
61                       i4_bool first_load_is_async=i4_T,
62                       i4_bool is_3d_capable=i4_F);
63
64  // called by async_read, do not call directly
65  void PRIVATE_callback(w32 count);
66
67  // should be called by main program at least 1/time per second, this routine
68  // checks to see if new wav needs to be loaded, return i4_F if song is done,
69  // if looping is on, poll will never report finished
70  i4_bool poll();
71
72  void pause();
73  void unpause();
74
75  void set_volume(i4_volume vol);
76  i4_bool load_failed() { return voice==0; }
77 
78  // this will free sound memory, and delete the file pointer and make sure there
79  // aren't any async_read's waiting to finish
80  ~i4_stream_wav_player();
81};
82
83
84#endif
Note: See TracBrowser for help on using the repository browser.