-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from sopro-dev/enh/new-proposal-structure
Enh/new proposal structure
- Loading branch information
Showing
84 changed files
with
583 additions
and
3,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: tagger | |
on: | ||
push: | ||
branches: | ||
- "*" | ||
- "main" | ||
|
||
jobs: | ||
tagger: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.1.4 | ||
v0.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package audio | ||
|
||
type AudioInfo struct { | ||
SampleRate int | ||
Channels int | ||
BitDepth int | ||
FloatFormat bool | ||
Verbose bool | ||
} | ||
|
||
type AudioFormat interface { | ||
Decode(data []byte, info AudioInfo) []byte | ||
Encode(audioData []byte, info AudioInfo) []byte | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// audio/formats/pcm/pcm.go | ||
package pcm | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/sopro-dev/sopro-core/audio" | ||
) | ||
|
||
type PCMFormat struct{} | ||
|
||
func (f *PCMFormat) Decode(data []byte, info audio.AudioInfo) []byte { | ||
log.Printf("Not implemented") | ||
return nil | ||
} | ||
|
||
func (f *PCMFormat) Encode(audioData []byte, info audio.AudioInfo) []byte { | ||
// convert float64 to byte | ||
data := make([]byte, len(audioData)) | ||
for i := 0; i < len(audioData); i++ { | ||
data[i] = byte(audioData[i]) | ||
} | ||
|
||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mulaw | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/sopro-dev/sopro-core/audio" | ||
"github.com/sopro-dev/sopro-core/audio/utils" | ||
) | ||
|
||
type MuLawFormat struct{} | ||
|
||
func (f *MuLawFormat) Decode(data []byte, info audio.AudioInfo) []byte { | ||
pcmData := make([]byte, len(data)*2) | ||
// remember that each byte need to be converted to two bytes | ||
for i := 0; i < len(data); i++ { | ||
|
||
newFrame := utils.DecodeULawToPCM(data[i : i+1]) | ||
pcmData[i*2] = newFrame[0] | ||
pcmData[i*2+1] = newFrame[1] | ||
|
||
} | ||
if info.Verbose { | ||
log.Println("[MuLaw][Decode] Decoded to PCM") | ||
log.Println("[MuLaw][Decode] PCM Data [0 :100]", pcmData[0:100]) | ||
log.Println("[MuLaw][Decode] PCM Data [100:200]", pcmData[100:200]) | ||
} | ||
|
||
return pcmData | ||
} | ||
|
||
func (f *MuLawFormat) Encode(audioData []byte, info audio.AudioInfo) []byte { | ||
log.Printf("Not implemented") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package audio | ||
|
||
import ( | ||
"errors" | ||
"unsafe" | ||
) | ||
|
||
type Transcoder struct { | ||
InputFormat AudioFormat | ||
OutputFormat AudioFormat | ||
} | ||
|
||
func NewTranscoder(inputFormat, outputFormat AudioFormat) *Transcoder { | ||
return &Transcoder{ | ||
InputFormat: inputFormat, | ||
OutputFormat: outputFormat, | ||
} | ||
} | ||
|
||
func (t *Transcoder) Transcode(inputData []byte, info AudioInfo) ([]byte, error) { | ||
err := validateAudioInfo(info) | ||
if err != nil { | ||
return nil, err | ||
} | ||
audioData := t.InputFormat.Decode(inputData, info) | ||
return t.OutputFormat.Encode(audioData, info), nil | ||
} | ||
|
||
var ( | ||
errInvalidBitDepth = errors.New("invalid bit depth") | ||
errInvalidNumChannels = errors.New("invalid number of channels") | ||
errInvalidSampleRate = errors.New("invalid sample rate") | ||
) | ||
|
||
func validateAudioInfo(info AudioInfo) error { | ||
if info.BitDepth != 8 && info.BitDepth != 16 && info.BitDepth != 24 && info.BitDepth != 32 { | ||
return errInvalidBitDepth | ||
} | ||
|
||
if info.Channels < 1 || info.Channels > 2 { | ||
return errInvalidNumChannels | ||
} | ||
|
||
if info.SampleRate < 1 { | ||
return errInvalidSampleRate | ||
} | ||
return nil | ||
} | ||
|
||
// IMPORTANT: DO NOT REMOVE THIS LINE | ||
// This line validates the size of the int16 type on the current platform, | ||
// panics if the size is not 2 bytes. | ||
var _ [unsafe.Sizeof(int16(0))]struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package audio | ||
|
||
import "testing" | ||
|
||
func TestValidateAudioInfo(t *testing.T) { | ||
// Test case 1: Valid audio info | ||
info := AudioInfo{BitDepth: 16, Channels: 2, SampleRate: 44100} | ||
err := validateAudioInfo(info) | ||
if err != nil { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
|
||
// Test case 2: Invalid bit depth | ||
info = AudioInfo{BitDepth: 5, Channels: 2, SampleRate: 44100} | ||
err = validateAudioInfo(info) | ||
if err == nil { | ||
t.Error("Expected an error for invalid bit depth") | ||
} | ||
if err != errInvalidBitDepth { | ||
t.Errorf("Expected error %v, got %v", errInvalidBitDepth, err) | ||
} | ||
|
||
// Test case 3: Invalid number of channels | ||
info = AudioInfo{BitDepth: 16, Channels: 0, SampleRate: 44100} | ||
err = validateAudioInfo(info) | ||
if err == nil { | ||
t.Error("Expected an error for invalid number of channels") | ||
} | ||
if err != errInvalidNumChannels { | ||
t.Errorf("Expected error %v, got %v", errInvalidNumChannels, err) | ||
} | ||
|
||
// Test case 4: Invalid sample rate | ||
info = AudioInfo{BitDepth: 16, Channels: 2, SampleRate: 0} | ||
err = validateAudioInfo(info) | ||
if err == nil { | ||
t.Error("Expected an error for invalid sample rate") | ||
} | ||
if err != errInvalidSampleRate { | ||
t.Errorf("Expected error %v, got %v", errInvalidSampleRate, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/binary" | ||
) | ||
|
||
// MergeSliceOfBytes merges multiple slices of bytes into a single slice | ||
func MergeSliceOfBytes(slices ...[]byte) []byte { | ||
var result []byte | ||
for _, s := range slices { | ||
result = append(result, s...) | ||
} | ||
return result | ||
} | ||
|
||
// IntToBytes converts an unsigned integer to a little-endian byte slice | ||
func IntToBytes(i interface{}) []byte { | ||
switch v := i.(type) { | ||
case uint32: | ||
buf := make([]byte, 4) | ||
binary.LittleEndian.PutUint32(buf, v) | ||
return buf | ||
case uint16: | ||
buf := make([]byte, 2) | ||
binary.LittleEndian.PutUint16(buf, v) | ||
return buf | ||
default: | ||
|
||
} | ||
return nil | ||
} |
Oops, something went wrong.