Comments (2)
Hi tg,
Welcome to the audio streaming world :)
Sure, that should be easily doable. What you want is the raw PCM data: those represent the individual samples, which are air pressure measurements taken at sequential points in time, e.g. 48 thousand times a second. You could literally create a sine wave with amplitude int16_max ÷ 2 to int16_min ÷ 2, and a period of 48e3/261.626 (iow 261.626 full periods per 48k samples), and if you passed that to an audio device configured to 48khz, you'd have a C. You just created a synthesizer. If you now create another similar sine, but with frequency 391.995Hz, you have a G. If you created a third array, ar
, looped over the other two, and literally did ar[i] = c[i] + g[i]
, you'd have a harmonic fifth.
Add in an E (329.628Hz), and you have a major C chord. However, because you started out at int16_max ÷ 2, and you're summing 3 streams, you could overflow; that's not ok. At the very least, you must do a "saturating sum", i.e. if int16_max - x < y ? int16_max : x + y
. This is called "(digital) clipping", and it sounds terrible. This is what you hear when you blow into a mic, or speak too loudly, or have your gain too high.
Tying it all together: what you want is an amplifier. At its core, the algorithm is: for i in range pcm { pcm[i] *= amp }
(or, rather: pcm[i] = saturating_mul(pcm[i], amp)
). How do you get amp from dB? decibels are a logarithmic scale, and the formula for getting an amplitude factor from gain (which is dB) is amp = 10^(gain/20)
. Wikipedia and Google have endless more info on this.
The _test files do some actual messing with sine waves, I strongly recommend having a look. I also recommend piping a sine wave through opus and back, dumping the raw PCM out to CSV and plotting that in Excel. You can do the same with any song, and you'll get the actual waveform. It helps make sense of it all.
Hope this helps!
Closing the ticket.
from opus.
Wow, thank you so much for such a fantastic response!
from opus.
Related Issues (20)
- transfer pcm to opus HOT 2
- run error HOT 2
- Forward error correction flag in decode (decode_fec flag) HOT 9
- How to find sample rate of a stream? HOT 2
- How can I play opus codec audio by using portaudio? HOT 1
- Opus 1.3 release,would we update to new version? HOT 1
- There is a difference between an opus stream (which is an ogg/opus stream) and raw opus data. .opus files are really .ogg files with opus data, which this package doesn't provide a way to write. It does have a reader for it (Stream type), but no writer yet (never bothered to because I haven't needed it so far, but feel free to submit a PR). HOT 2
- transfer pcm to raw opus HOT 7
- "checkptr: unsafe pointer arithmetic" when using go race detector HOT 1
- How to complie in cross platform? HOT 5
- Inconsistent types in README HOT 1
- encoder: invalid argument HOT 1
- Byte slice to int16 slice. HOT 2
- How to destroy en(de)coder state? HOT 2
- Get audio from microphone and encode to ogg HOT 1
- Strange distortion when decoding HOT 6
- implicit declaration of function 'OPUS_GET_IN_DTX' HOT 8
- wasm env HOT 2
- Question: is it possible to build against libopus v1.5.(2) to be able to use the new features #108 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opus.