Documentation
¶
Overview ¶
Package audio provides utilities for converting between PCM and μ-law audio formats.
Index ¶
- func CalculatePCMDuration(audioFormat *audiopb.Format, dataSize int) (time.Duration, error)
- func CalculateWAVDuration(bytes []byte) (time.Duration, error)
- func Mulaw8ToPCM16(mulaw []byte) []byte
- func PCM16ToMulaw8(pcmBytes []byte) []byte
- func PCMToWAV(pcmData []byte, audioFormat *audiopb.Format) []byte
- func ResamplePCM16(input []byte, fromRate, toRate int32) []byte
- func WAVToPCM16(wavData []byte) (pcmData []byte, sampleRate int32, numChannels int16, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculatePCMDuration ¶
CalculatePCMDuration calculates the duration of audio data given its parameters. dataSize is the total size of audio data in bytes. sampleRate is the number of samples per second (Hz). channels is the number of audio channels (1 for mono, 2 for stereo). bitsPerSample is the number of bits per sample (e.g., 16 for PCM16).
func Mulaw8ToPCM16 ¶
MulawToPCM converts μ-law encoded audio to 16-bit PCM (little-endian). Input: μ-law bytes (8-bit samples) Output: PCM bytes (16-bit samples, little-endian)
func PCM16ToMulaw8 ¶
PCMToMulaw converts 16-bit PCM to μ-law encoded audio. Input: PCM bytes (16-bit samples, little-endian) Output: μ-law bytes (8-bit samples)
func PCMToWAV ¶
PCMToWAV converts raw PCM audio to WAV format pcmData: PCM samples in the format specified by audioFormat audioFormat: specifies sample rate, number of channels, and bits per sample
func ResamplePCM16 ¶
ResamplePCM16 resamples 16-bit PCM audio from one sample rate to another using simple linear interpolation (suitable for downsampling)
func WAVToPCM16 ¶
WAVToPCM16 extracts raw 16-bit PCM audio data from a WAV file. Returns the PCM data, sample rate, number of channels, and any error. The function validates the WAV header and ensures it contains 16-bit PCM audio.
Types ¶
This section is empty.