-
Notifications
You must be signed in to change notification settings - Fork 17
/
Getting Started.txt
38 lines (31 loc) · 1.18 KB
/
Getting Started.txt
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
This package implements Oggfile support to encode/decode .opus files using Concentus.
TO ENCODE:
using (FileStream fileOut = new FileStream(opusfile, FileMode.Create))
{
OpusEncoder encoder = OpusCodecFactory.CreateEncoder(48000, 2, OpusApplication.OPUS_APPLICATION_AUDIO);
encoder.Bitrate = 96000;
OpusTags tags = new OpusTags();
tags.Fields[OpusTagName.Title] = "Song Title";
tags.Fields[OpusTagName.Artist] = "Artist";
OpusOggWriteStream oggOut = new OpusOggWriteStream(encoder, fileOut, tags, inputSampleRate: 44100); // instead of 44100 pass the actual input sample rate of your audio here
while (HasMoreAudio())
{
short[] packet = ReadSomeAudio();
oggOut.WriteSamples(packet, 0, packet.Length);
}
oggOut.Finish(); // this closes the underlying stream
}
TO DECODE:
using (FileStream fileIn = new FileStream(opusfile, FileMode.Open))
{
OpusDecoder decoder = OpusCodecFactory.CreateDecoder(48000, 2);
OpusOggReadStream oggIn = new OpusOggReadStream(decoder, fileIn);
while (oggIn.HasNextPacket)
{
short[] packet = oggIn.DecodeNextPacket();
if (packet != null)
{
DoSomethingWithAudio(packet);
}
}
}