summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rhimport/fetcher.go41
-rw-r--r--rhimport/wave_generator.go2
2 files changed, 40 insertions, 3 deletions
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go
index 1a40e71..db7ac3e 100644
--- a/rhimport/fetcher.go
+++ b/rhimport/fetcher.go
@@ -621,7 +621,43 @@ func fetchFileSilence(ctx *Context, res *Result, uri *url.URL) error {
return err
}
size := wav.GetFileSize()
- wav.generator = NewSilenceGenerator()
+ wav.generator = newSilenceGenerator()
+
+ ctx.reportProgress(1, "fetching", 0.0, float64(size))
+ return fetchFileConvert(ctx, res, wav, int64(size))
+}
+
+//***********************
+//** sine://
+
+func fetchFileSine(ctx *Context, res *Result, uri *url.URL) error {
+ ctx.dbglog.Printf("Sine-Wave fetcher for '%s'", ctx.SourceUri)
+
+ d, err := strconv.ParseUint(uri.Host, 10, 32)
+ if err != nil {
+ res.ResponseCode = http.StatusBadRequest
+ res.ErrorString = "invalid duration (must be a positive integer)"
+ return nil
+ }
+ duration := time.Duration(d) * 100 * time.Millisecond
+
+ f, err := strconv.ParseUint(strings.TrimPrefix(uri.Path, "/"), 10, 32)
+ if err != nil {
+ res.ResponseCode = http.StatusBadRequest
+ res.ErrorString = fmt.Sprintf("invalid frequency: (must be a positive integer)")
+ return nil
+ }
+ frequency := float64(f)
+
+ ctx.SourceFile = "sine.wav"
+ ctx.Title = fmt.Sprintf("%v of @ %.1f Hz...", duration, frequency)
+ ctx.ExtraMetaData["TITLE"] = ctx.Title
+ wav, err := newPCMWavFile(uint32(ctx.conf.SampleRate), 16, uint16(ctx.Channels), duration)
+ if err != nil {
+ return err
+ }
+ size := wav.GetFileSize()
+ wav.generator = newSinusGenerator(0.0, frequency)
ctx.reportProgress(1, "fetching", 0.0, float64(size))
return fetchFileConvert(ctx, res, wav, int64(size))
@@ -665,9 +701,10 @@ type fetchFunc func(*Context, *Result, *url.URL) (err error)
var (
fetchers = map[string]fetchFunc{
- "local": fetchFileLocal,
"tmp": fetchFileTmp,
+ "local": fetchFileLocal,
"silence": fetchFileSilence,
+ "sine": fetchFileSine,
"attachment": fetchFileAttachment,
}
curlProtos = map[string]bool{
diff --git a/rhimport/wave_generator.go b/rhimport/wave_generator.go
index 7816bc0..0f2f16d 100644
--- a/rhimport/wave_generator.go
+++ b/rhimport/wave_generator.go
@@ -176,7 +176,7 @@ func newPCMWavFile(sampleRate uint32, sampleDepth uint16, channels uint16, lengt
type silenceGenerator struct {
}
-func NewSilenceGenerator() *silenceGenerator {
+func newSilenceGenerator() *silenceGenerator {
return &silenceGenerator{}
}