-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
592 additions
and
239 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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package gopi | ||
|
||
/* | ||
This file contains definitions for audio data: | ||
* Audio representation | ||
* Input and output audio devices | ||
Resampling of audio is represented in the "media" interfaces | ||
*/ | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// TYPES | ||
|
||
// AudioFormat defines the audio format | ||
type AudioFormat uint | ||
|
||
// AudioChannelLayout represents number of channels and layout of those channels | ||
type AudioChannelLayout struct { | ||
Channels uint | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// AUDIO INTERFACES | ||
|
||
type AudioManager interface { | ||
// OpenDefaultSink opens default output device | ||
OpenDefaultSink() (AudioContext, error) | ||
|
||
// Close audio stream | ||
Close(AudioContext) error | ||
} | ||
|
||
type AudioContext interface { | ||
// Write data to audio output device | ||
Write(MediaFrame) error | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// CONSTANTS | ||
|
||
const ( | ||
AUDIO_FMT_NONE AudioFormat = iota | ||
AUDIO_FMT_U8 // unsigned 8 bits | ||
AUDIO_FMT_U8P // unsigned 8 bits, planar | ||
AUDIO_FMT_S16 // signed 16 bits | ||
AUDIO_FMT_S16P // signed 16 bits, planar | ||
AUDIO_FMT_S32 // signed 32 bits | ||
AUDIO_FMT_S32P // signed 32 bits, planar | ||
AUDIO_FMT_F32 // float32 | ||
AUDIO_FMT_F32P // float32, planar | ||
AUDIO_FMT_F64 // float64 | ||
AUDIO_FMT_F64P // float64, planar | ||
AUDIO_FMT_S64 // signed 64 bits | ||
AUDIO_FMT_S64P // signed 64 bits, planar | ||
) | ||
|
||
var ( | ||
AudioLayoutMono = AudioChannelLayout{1} | ||
AudioLayoutStereo = AudioChannelLayout{2} | ||
) | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// STRINGIFY | ||
|
||
func (f AudioFormat) String() string { | ||
switch f { | ||
case AUDIO_FMT_NONE: | ||
return "AUDIO_FMT_NONE" | ||
case AUDIO_FMT_U8: | ||
return "AUDIO_FMT_U8" | ||
case AUDIO_FMT_U8P: | ||
return "AUDIO_FMT_U8P" | ||
case AUDIO_FMT_S16: | ||
return "AUDIO_FMT_S16" | ||
case AUDIO_FMT_S16P: | ||
return "AUDIO_FMT_S16P" | ||
case AUDIO_FMT_S32: | ||
return "AUDIO_FMT_S32" | ||
case AUDIO_FMT_S32P: | ||
return "AUDIO_FMT_S32P" | ||
case AUDIO_FMT_F32: | ||
return "AUDIO_FMT_F32" | ||
case AUDIO_FMT_F32P: | ||
return "AUDIO_FMT_F32P" | ||
case AUDIO_FMT_F64: | ||
return "AUDIO_FMT_F64" | ||
case AUDIO_FMT_F64P: | ||
return "AUDIO_FMT_F64P" | ||
case AUDIO_FMT_S64: | ||
return "AUDIO_FMT_S64" | ||
case AUDIO_FMT_S64P: | ||
return "AUDIO_FMT_S64P" | ||
default: | ||
return "[?? Invalid AudioFormat value]" | ||
} | ||
} |
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,67 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/djthorpe/gopi/v3" | ||
) | ||
|
||
type app struct { | ||
gopi.Unit | ||
gopi.MediaManager | ||
gopi.Logger | ||
|
||
filename string | ||
} | ||
|
||
func (this *app) Define(cfg gopi.Config) error { | ||
return nil | ||
} | ||
|
||
func (this *app) New(cfg gopi.Config) error { | ||
this.Require(this.Logger, this.MediaManager) | ||
|
||
if args := cfg.Args(); len(args) != 1 { | ||
return gopi.ErrBadParameter.WithPrefix("Missing filename") | ||
} else if stat, err := os.Stat(args[0]); err != nil { | ||
return gopi.ErrBadParameter.WithPrefix(args[0]) | ||
} else if stat.Mode().IsRegular() == false { | ||
return gopi.ErrBadParameter.WithPrefix(args[0]) | ||
} else { | ||
this.filename = args[0] | ||
} | ||
|
||
// Return success | ||
return nil | ||
} | ||
|
||
func (this *app) Run(ctx context.Context) error { | ||
// Open the file, decode the audio | ||
if file, err := this.OpenFile(this.filename); err != nil { | ||
return err | ||
} else if err := this.Decode(ctx, file); err != nil { | ||
return err | ||
} | ||
|
||
// Return success | ||
return nil | ||
} | ||
|
||
func (this *app) Decode(ctx context.Context, file gopi.MediaInput) error { | ||
// Use the first video stream found | ||
streams := file.StreamsForFlag(gopi.MEDIA_FLAG_AUDIO) | ||
if len(streams) == 0 { | ||
return gopi.ErrNotFound.WithPrefix("Audio stream") | ||
} else { | ||
this.Print(file.StreamForIndex(streams[0])) | ||
} | ||
|
||
// Decode frames | ||
return file.Read(ctx, streams[0:1], func(ctx gopi.MediaDecodeContext, packet gopi.MediaPacket) error { | ||
return file.DecodeFrameIterator(ctx, packet, func(frame gopi.MediaFrame) error { | ||
this.Print("Decoded", ctx.Frame(), " => ", frame) | ||
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,11 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/djthorpe/gopi/v3/pkg/tool" | ||
) | ||
|
||
func main() { | ||
os.Exit(tool.CommandLine("audioid", os.Args[1:], new(app))) | ||
} |
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,5 @@ | ||
package main | ||
|
||
import ( | ||
_ "github.com/djthorpe/gopi/v3/pkg/media/ffmpeg" | ||
) |
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
Oops, something went wrong.