Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #11

Merged
merged 15 commits into from
Jan 28, 2023
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Trascoding a file from ulaw to wav pcm with CLI
go get -v github.com/pablodz/sopro
```

## Contribution

Every contribution is welcome. If you want to contribute, please create a branch from `master` and create a PR to `develop` branch.

## Methods planned to be implemented

- [x] Chunked
Expand Down
16 changes: 7 additions & 9 deletions cmd/sopro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/pablodz/sopro/pkg/cpuarch"
"github.com/pablodz/sopro/pkg/encoding"
"github.com/pablodz/sopro/pkg/fileformat"
"github.com/pablodz/sopro/pkg/sopro"
"github.com/pablodz/sopro/pkg/transcoder"
"github.com/urfave/cli/v2"
)

const VERSION = "v0.1.3"

func main() {

app := &cli.App{
Name: "sopro",
Usage: "High performance audio processing tool",
Expand All @@ -26,7 +26,6 @@ func main() {
Name: "transcoder",
Usage: "Transcode audio files",
Flags: []cli.Flag{

&cli.IntFlag{
Name: "method",
Usage: "transcode method",
Expand Down Expand Up @@ -115,7 +114,6 @@ func main() {
},

Action: func(ctx *cli.Context) error {

fmt.Println("[Version] ", ctx.App.Version)

methodT := ctx.Int("method")
Expand Down Expand Up @@ -213,10 +211,10 @@ func main() {
// create a transcoder
t := &transcoder.Transcoder{
MethodT: methodT, // method.BIT_LOOKUP_TABLE=1
SourceConfigs: transcoder.TranscoderAudioConfig{
InConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
TargetConfigs: transcoder.TranscoderAudioConfig{
OutConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
SizeBuffer: buffer,
Expand All @@ -225,9 +223,9 @@ func main() {

// Transcode the file
err = t.Mulaw2Wav(
&transcoder.AudioFileIn{
&sopro.In{
Data: in,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_MULAW,
Config: audioconfig.MulawConfig{
BitDepth: inputBits,
Expand All @@ -237,9 +235,9 @@ func main() {
},
},
},
&transcoder.AudioFileOut{
&sopro.Out{
Data: out,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_WAV,
Config: audioconfig.WavConfig{
BitDepth: outputBits,
Expand Down
73 changes: 73 additions & 0 deletions examples/band_limited_sinc_interpolation/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"os"

"github.com/pablodz/sopro/pkg/audioconfig"
"github.com/pablodz/sopro/pkg/cpuarch"
"github.com/pablodz/sopro/pkg/encoding"
"github.com/pablodz/sopro/pkg/fileformat"
"github.com/pablodz/sopro/pkg/resampler"
"github.com/pablodz/sopro/pkg/sopro"
)

func main() {
// Open the input file
in, err := os.Open("./internal/samples/v1_16b_16000.wav")
if err != nil {
panic(err)
}
defer in.Close()

// Create the output file
out, err := os.Create("./internal/samples/v1_16b_8000_2.wav")
if err != nil {
panic(err)
}
defer out.Close()

// create a transcoder
r := &resampler.Resampler{
MethodR: resampler.BAND_LIMITED_INTERPOLATION,
InConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
OutConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
SizeBuffer: 4096,
Verbose: true,
}

// Transcode the file
err = r.Wav(
&sopro.In{
Data: in,
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_WAV,
Config: audioconfig.WavConfig{
BitDepth: 16,
Channels: 1,
Encoding: encoding.SPACE_LINEAR, // ulaw is logarithmic
SampleRate: 16000,
},
},
},
&sopro.Out{
Data: out,
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_WAV,
Config: audioconfig.WavConfig{
BitDepth: 8,
Channels: 1,
Encoding: encoding.SPACE_LINEAR,
SampleRate: 16000,
},
},
},
)

if err != nil {
panic(err)
}
}
13 changes: 7 additions & 6 deletions examples/bytesulaw2wav/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pablodz/sopro/pkg/encoding"
"github.com/pablodz/sopro/pkg/fileformat"
"github.com/pablodz/sopro/pkg/method"
"github.com/pablodz/sopro/pkg/sopro"
"github.com/pablodz/sopro/pkg/transcoder"
)

Expand All @@ -27,10 +28,10 @@ func main() {
// create a transcoder
t := &transcoder.Transcoder{
MethodT: method.BIT_LOOKUP_TABLE,
SourceConfigs: transcoder.TranscoderAudioConfig{
InConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
TargetConfigs: transcoder.TranscoderAudioConfig{
OutConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
SizeBuffer: 1024,
Expand All @@ -39,9 +40,9 @@ func main() {

// Transcode the file
err = t.Mulaw2Wav(
&transcoder.AudioFileIn{
&sopro.In{
Data: in,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_MULAW,
Config: audioconfig.MulawConfig{
BitDepth: 8,
Expand All @@ -51,9 +52,9 @@ func main() {
},
},
},
&transcoder.AudioFileOut{
&sopro.Out{
Data: out,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_WAV,
Config: audioconfig.WavConfig{
BitDepth: 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pablodz/sopro/pkg/encoding"
"github.com/pablodz/sopro/pkg/fileformat"
"github.com/pablodz/sopro/pkg/resampler"
"github.com/pablodz/sopro/pkg/transcoder"
"github.com/pablodz/sopro/pkg/sopro"
)

func main() {
Expand All @@ -27,23 +27,23 @@ func main() {
defer out.Close()

// create a transcoder
t := &transcoder.Transcoder{
r := &resampler.Resampler{
MethodR: resampler.LINEAR_INTERPOLATION,
SourceConfigs: transcoder.TranscoderAudioConfig{
InConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
TargetConfigs: transcoder.TranscoderAudioConfig{
OutConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
SizeBuffer: 1024,
Verbose: true,
}

// Transcode the file
err = t.Wav2Wav(
&transcoder.AudioFileIn{
err = r.Wav(
&sopro.In{
Data: in,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_WAV,
Config: audioconfig.WavConfig{
BitDepth: 16,
Expand All @@ -53,9 +53,9 @@ func main() {
},
},
},
&transcoder.AudioFileOut{
&sopro.Out{
Data: out,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_WAV,
Config: audioconfig.WavConfig{
BitDepth: 16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pablodz/sopro/pkg/encoding"
"github.com/pablodz/sopro/pkg/fileformat"
"github.com/pablodz/sopro/pkg/method"
"github.com/pablodz/sopro/pkg/sopro"
"github.com/pablodz/sopro/pkg/transcoder"
)

Expand All @@ -29,10 +30,10 @@ func main() {
// create a transcoder
t := &transcoder.Transcoder{
MethodT: method.BIT_LOOKUP_TABLE,
SourceConfigs: transcoder.TranscoderAudioConfig{
InConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
TargetConfigs: transcoder.TranscoderAudioConfig{
OutConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
SizeBuffer: 1024,
Expand All @@ -41,9 +42,9 @@ func main() {

// Transcode the file
err = t.Mulaw2Wav(
&transcoder.AudioFileIn{
&sopro.In{
Data: in,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_MULAW,
Config: audioconfig.MulawConfig{
BitDepth: 8,
Expand All @@ -53,9 +54,9 @@ func main() {
},
},
},
&transcoder.AudioFileOut{
&sopro.Out{
Data: out,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_WAV,
Config: audioconfig.WavConfig{
BitDepth: 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pablodz/sopro/pkg/encoding"
"github.com/pablodz/sopro/pkg/fileformat"
"github.com/pablodz/sopro/pkg/method"
"github.com/pablodz/sopro/pkg/sopro"
"github.com/pablodz/sopro/pkg/transcoder"
)

Expand All @@ -19,6 +20,7 @@ func main() {
}
defer in.Close()

defer println("Done!", "file:", "./internal/samples/result_sample_ulaw_mono_8000_le_lpcm.wav ")
// Create the output file
out, err := os.Create("./internal/samples/result_sample_ulaw_mono_8000_le_lpcm.wav")
if err != nil {
Expand All @@ -29,10 +31,10 @@ func main() {
// create a transcoder
t := &transcoder.Transcoder{
MethodT: method.BIT_LOOKUP_TABLE,
SourceConfigs: transcoder.TranscoderAudioConfig{
InConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
TargetConfigs: transcoder.TranscoderAudioConfig{
OutConfigs: sopro.AudioConfig{
Endianness: cpuarch.LITTLE_ENDIAN,
},
SizeBuffer: 1024,
Expand All @@ -41,9 +43,9 @@ func main() {

// Transcode the file
err = t.Mulaw2Wav(
&transcoder.AudioFileIn{
&sopro.In{
Data: in,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_MULAW,
Config: audioconfig.MulawConfig{
BitDepth: 8,
Expand All @@ -53,9 +55,9 @@ func main() {
},
},
},
&transcoder.AudioFileOut{
&sopro.Out{
Data: out,
AudioFileGeneral: transcoder.AudioFileGeneral{
AudioFileGeneral: sopro.AudioFileGeneral{
Format: fileformat.AUDIO_WAV,
Config: audioconfig.WavConfig{
BitDepth: 16,
Expand Down
8 changes: 0 additions & 8 deletions pkg/audioconfig/3gp.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/audioconfig/aiff.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/audioconfig/alac.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/audioconfig/au.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/audioconfig/m4a.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/audioconfig/mulaw.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package audioconfig

// MulawConfig is a struct that contains the configuration of a MULAW (RAW) audio file.
type MulawConfig struct {
SampleRate int // the sample rate in Hertz
BitDepth int // the bit depth (e.g. 8, 16, 24)
Channels int // the number of channels (e.g. 1, 2)
Encoding int // the encoding format (e.g. "UNSIGNED", "SIGNED", "FLOAT")
// Endianness string // the endianness of the audio data (e.g. "BIG", "LITTLE") The endianess is defined by the processor architecture
}
6 changes: 0 additions & 6 deletions pkg/audioconfig/ogg.go

This file was deleted.

Loading