Created
February 4, 2019 18:13
-
-
Save brettbuddin/d04b5b53aff8b87cb8144d3419574acf to your computer and use it in GitHub Desktop.
EricaSynths Pico Drum Samples for Expert Sleepers Disting
This file contains hidden or 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
# frozen_string_literal: true | |
require 'msgpack' | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
require 'wavefile' | |
require 'fileutils' | |
DATA_ROOT = 'data' | |
class RawData | |
def to_msgpack_ext | |
raise NotImplementedError | |
end | |
def self.from_msgpack_ext(data) | |
data | |
end | |
end | |
MessagePack::DefaultFactory.register_type(0x1a, RawData) | |
def download_pack_list | |
now = Time.now.to_i | |
pack_list_uri = URI("http://data.ericasynths.lv/picodrum/pack_list.json?_=#{now}") | |
JSON.parse(Net::HTTP.get(pack_list_uri)) | |
end | |
def download_pack(filename) | |
pack_uri = URI("http://data.ericasynths.lv/picodrum/#{filename}") | |
blob = Net::HTTP.get(pack_uri) | |
MessagePack.unpack(blob) | |
end | |
download_pack_list.each do |pack| | |
puts "#{pack['file']} (v#{pack['version']})" | |
pack_dir = pack['file'].sub('.bin', '') + "_v#{pack['version']}" | |
data_dir = File.join(DATA_ROOT, pack_dir) | |
FileUtils.mkdir_p(data_dir) | |
playlist = <<~HEREDOC | |
disting playlist v1 | |
-loop=0 | |
-gap=0 | |
-fadeIn=0 | |
-fadeOut=0 | |
HEREDOC | |
download_pack(pack['file']).each do |sample| | |
puts "-- #{sample['name']}" | |
begin | |
reader = WaveFile::Reader.new(StringIO.new(sample['data'])) | |
rescue => e | |
puts "error: #{e.message}" | |
next | |
end | |
wav_filepath = File.join(data_dir, sample['name']) | |
dest_fmt = WaveFile::Format.new(:mono, :pcm_16, 44100) | |
WaveFile::Writer.new(wav_filepath, dest_fmt) do |writer| | |
reader.each_buffer { |buffer| writer.write(buffer) } | |
end | |
playlist += "#{sample['name']}\n" | |
end | |
playlist_filepath = File.join(data_dir, 'playlist.txt') | |
File.open(playlist_filepath, 'w') { |file| file.write(playlist) } | |
end |
This file contains hidden or 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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem 'msgpack' | |
gem 'wavefile' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment