diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-09-03 19:20:11 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-09-03 19:20:11 +0200 |
commit | d104bd746605cb38977173beb079ebac7e8fa0ce (patch) | |
tree | 2f3d25cd40f67a946f1fd455cca4187c371143d5 /applause.lua | |
parent | 148195537704906dd9a50cea8442a4df0cd8b16f (diff) | |
download | applause2-d104bd746605cb38977173beb079ebac7e8fa0ce.tar.gz |
SndfileStream() supports raw files now, by passing through samplerate, channels and libsndfile format
Diffstat (limited to 'applause.lua')
-rw-r--r-- | applause.lua | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/applause.lua b/applause.lua index e257fb2..1a67ed7 100644 --- a/applause.lua +++ b/applause.lua @@ -303,6 +303,17 @@ function Stream:scale(v1, v2) end) end +-- same as Stream:scale() but for values between [0, 127] +-- (ie. MIDI CC values) +function Stream:ccscale(v1, v2) + local lower = v2 and v1 or 0 + local upper = v2 or v1 + + return self:map(function(x) + return (x/127)*(upper - lower) + lower + end) +end + function Stream:scan(fnc) return ScanStream:new(self, fnc) end @@ -943,12 +954,17 @@ end SndfileStream = DeriveClass(Stream) -function SndfileStream:ctor(filename) +function SndfileStream:ctor(filename, samplerate, channels, format) -- FIXME: This fails if the file is not at the -- correct sample rate. Need to resample... - local handle = sndfile:new(filename, "SFM_READ") + -- NOTE: samplerate and channels are ignored unless SF_FORMAT_RAW + -- files are read. + local handle = sndfile:new(filename, "SFM_READ", + samplerate, channels, format) self.filename = filename + self.samplerate = handle.info.samplerate self.channels = handle.info.channels + self.format = handle.info.format self.frames = tonumber(handle.info.frames) handle:close() @@ -969,7 +985,8 @@ function SndfileStream:gtick() -- read pointer which is important when reusing the stream. -- NOTE: We could do this with a single handle per object but -- by maintaining our own read position and seeking before reading. - local handle = sndfile:new(self.filename, "SFM_READ") + local handle = sndfile:new(self.filename, "SFM_READ", + self.samplerate, self.channels, self.format) -- Make sure that we are still reading the same file; -- at least with the same meta-data. |