source: golgotha/src/i4/loaders/wav_load.cc @ 608

Last change on this file since 608 was 80, checked in by Sam Hocevar, 15 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: 1.7 KB
Line 
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#include "loaders/wav_load.hh"
10#include "file/file.hh"
11
12// system independently ordered 4 byte id
13inline w32 CtoID(char a, char b, char c, char d)
14{
15  return l_to_msb( (((w32)a)<<24) | (((w32)b)<<16) | (((w32)c)<<8) | ((w32)d) );
16}
17
18
19i4_bool i4_load_wav_info(i4_file_class *f, i4_sound_info &info)
20{
21  w32 end_pos, chunk_type, len;
22
23  // look for RIFF signature
24  if (f->read_32() != CtoID('R','I','F','F'))
25    return i4_F;
26
27  end_pos = f->read_32();
28  end_pos += f->tell();
29
30  // look for WAVE sig
31  if (f->read_32() != CtoID('W','A','V','E'))
32    return i4_F;
33
34  // read all data chunks
35  while (f->tell() < end_pos)
36  {
37    chunk_type = f->read_32();
38    len = f->read_32();
39
40    if      (chunk_type == CtoID('f','m','t',' '))
41    {
42      // sound format info
43      f->read_16();
44      info.channels = f->read_16();
45      info.sample_rate = f->read_32();
46      f->read_32();
47      f->read_16();
48      info.sample_size = f->read_16()/8;
49
50      f->seek(f->tell() + len - 16);
51    }
52    else if (chunk_type == CtoID('d','a','t','a'))
53    {
54      info.size = len;
55
56      return i4_T;
57    }
58    else
59      f->seek(f->tell() + len);
60
61  }
62
63  return i4_F;
64}
Note: See TracBrowser for help on using the repository browser.