MCPcopy Create free account
hub / github.com/crownengine/crown / parse

Function parse

src/resource/sound_ogg.cpp:37–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35namespace ogg
36{
37 s32 parse(Sound &s, Buffer &buf, CompileOptions &opts)
38 {
39 OggStreamMetadata ogg;
40 const u8 *data = (u8 *)array::begin(buf);
41 const u32 size = array::size(buf);
42 int p = 0;
43 int q = 1;
44
45 int used;
46 int error;
47 stb_vorbis *v;
48 while (true) {
49 v = stb_vorbis_open_pushdata(data, q, &used, &error, NULL);
50 if (v != NULL)
51 break;
52
53 RETURN_IF_FALSE(OGG, error == VORBIS_need_more_data
54 , opts
55 , "stb_vorbis_open_pushdata: error: %d"
56 , error
57 );
58 q += 1;
59 }
60
61 RETURN_IF_FALSE(OGG, v != NULL, opts, "stb_vorbis_open_pushdata: error: %d", error);
62 p += used;
63 ogg.headers_size = p;
64
65 stb_vorbis_info info = stb_vorbis_get_info(v);
66 ogg.alloc_buffer_size = info.setup_memory_required
67 + info.setup_temp_memory_required
68 + info.temp_memory_required
69 ;
70 ogg.max_frame_size = info.max_frame_size;
71
72 // Decode SOUND_PCM_MS worth of audio samples.
73 unsigned int wanted_n = info.sample_rate / 1000 * SOUND_PCM_MS;
74 ogg.num_samples_skip = wanted_n;
75
76 FileBuffer fb(buf);
77 fb.seek(p);
78
79 p = 0;
80 unsigned int total_n = 0;
81 unsigned char *mem = (unsigned char *)default_allocator().allocate(info.max_frame_size);
82
83 // Decode up to wanted_n samples.
84 while (total_n < wanted_n) {
85 float **output;
86 int n;
87 q = info.max_frame_size;
88
89 retry:
90 if (q > (int)size - p)
91 q = (int)size - p;
92 if (p < q)
93 fb.read(&mem[p], q - p);
94

Callers

nothing calls this directly

Calls 14

stb_vorbis_open_pushdataFunction · 0.85
stb_vorbis_get_infoFunction · 0.85
memmoveFunction · 0.85
stb_vorbis_closeFunction · 0.85
beginFunction · 0.50
sizeFunction · 0.50
resizeFunction · 0.50
seekMethod · 0.45
allocateMethod · 0.45
readMethod · 0.45
end_of_fileMethod · 0.45

Tested by

no test coverage detected