source: golgotha/src/i4/loaders/mp3/mp3_decoder.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 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.5 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 "main/main.hh"
10#include "error/alert.hh"
11#include "error/error.hh"
12#include "file/file.hh"
13#include "string/str_checksum.hh"
14#include "memory/malloc.hh"
15#include "loaders/mp3_load.hh"
16#include "loaders/wav_load.hh"
17#include "status/status.hh"
18
19
20
21void write_header(i4_file_class *fp, i4_sound_info &fmt)
22{
23  fp->write("RIFF",4);
24  fp->write_32(36+fmt.size);       // 36 + snd->size
25  fp->write("WAVE", 4);
26  fp->write("fmt ", 4);
27
28  fp->write_32(16);        // size of chunk
29
30  fp->write_16(1);         // data type
31
32  fp->write_16(fmt.channels);           // num channels
33  fp->write_32(fmt.sample_rate);   // sample rate
34  fp->write_32(fmt.sample_rate*
35               fmt.sample_size*fmt.channels);       // snd->sample_rate * snd->sample_size
36  fp->write_16(fmt.sample_size * fmt.channels);
37  fp->write_16(fmt.sample_size*8);
38
39
40  fp->write("data",4);
41  fp->write_32(fmt.size);       // snd->size
42
43}
44
45void i4_main(w32 argc, i4_const_str *argv)
46{
47  i4_init();
48
49
50  i4_file_class *in=i4_open("in.mp3");
51  i4_file_class *out=i4_open("out.wav", I4_WRITE);
52
53  i4_sound_info fmt;
54//   fmt.channels=2;
55//   fmt.sample_rate=44*1024;
56//   fmt.sample_size=2;
57//   fmt.size=500000;
58
59  write_header(out, fmt);
60  int header_size=out->tell();
61
62  i4_status_class *status=i4_create_status("decoding");
63
64  if (i4_load_mp3(in, out, fmt, status))
65    i4_warning("decode success");
66  else
67    i4_warning("decode failed");
68
69  int size=out->tell();
70  out->seek(0);
71
72  write_header(out, fmt);
73  out->seek(size);
74
75  delete status;
76
77  delete in;
78  delete out;
79
80 
81  in=i4_open("out.wav");
82  if (i4_load_wav_info(in, fmt))
83  {
84    i4_warning("wrote :\n"
85               "sample size = %d\n"
86               "channels    = %d\n"
87               "sample_rate = %d\n"
88               "size        = %d\n",
89               fmt.sample_size,
90               fmt.channels,
91               fmt.sample_rate,
92               fmt.size);
93  }
94  delete in;
95 
96  i4_uninit();
97
98}
Note: See TracBrowser for help on using the repository browser.