summaryrefslogtreecommitdiff
path: root/rhimport
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-08-04 16:52:59 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-08-04 16:52:59 (GMT)
commit0d3025b170012a689793a42060bfdcc59843d057 (patch)
tree8981d2ec77367f7eac39d81235e78621802e1022 /rhimport
parentdd771e3d6e2226b6ce3ac764626c89810fbc4366 (diff)
added sine:// fetcher
Diffstat (limited to 'rhimport')
-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{}
}