Skip to content

Instantly share code, notes, and snippets.

View rniwase's full-sized avatar

Ryohei Niwase rniwase

  • Tsukuba, Ibaraki Japan
View GitHub Profile
@rniwase
rniwase / any2wav.py
Last active August 29, 2015 14:16
バイナリにRIFFフォーマットのヘッダを追加してWAVで保存します
#!/usr/bin/env python
# usage : python any2wav.py <inputfile> <outputfile>
import sys
import struct
def uint2ToStr(x) : return struct.pack('<H',x)
def uint4ToStr(x) : return struct.pack('<I',x)
@rniwase
rniwase / jsbach_beep.py
Last active September 17, 2017 18:46
「主よ、人の望みの喜びよ」をBeepで演奏 (winのみ)
import winsound
import time
frq = [392, 587, 659, 740, 784, 880, 988, 1047, 1175, 1319, 1480, 1568]
note = [-3, 1, 2, 3, 5, 4, 4, 6, 5, 5, 8, 7,
8, 5, 3, 1, 2, 3, 4, 5, 6, 5, 4, 3,
2, 3, 1, 0, 1, 2, -2, 0, 2, 4, 3, 2,
3, 1, 2, 3, 5, 4, 4, 6, 5, 5, 8, 7,
8, 5, 3, 1, 2, 3, -1, 5, 4, 3, 2, 1,
-2, 1, 0, 1, 3, 5, 8, 5, 3, 1, 3, 5, 8]
@rniwase
rniwase / Spectrum_logscale.pde
Created February 8, 2016 00:58
Processing 3.0.1でオーディオ入力からログスケールのスペクトルを描画する
/*
* オーディオ入力からログスケールのスペクトルを描画
* Processing 3.0.1 要Soundライブラリ
*/
import processing.sound.*;
int bands = 256; // バンド数
int average = 4; // 移動平均数
float minrange = -50.0; // 表示最小振幅 [dBFS]
@rniwase
rniwase / Spectrogram.pde
Created February 8, 2016 12:04
Processing 3.0.1 オーディオ入力の声紋を表示
/*
* オーディオ入力の声紋を表示
* Processing 3.0.1 要Soundライブラリ
*/
import processing.sound.*;
int bands = 256; // バンド数
float minrange = -60.0; // 表示最小振幅 [dBFS]
# it's fucking noise
import sys
import random
import time
ROW = 32
COLUMN = 64
def clear_window():
@rniwase
rniwase / isbn2recdata.py
Last active March 17, 2021 05:45
テキストファイルからISBNチェックディジット検証・NDLから所蔵データ取得
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ISBNコードが羅列されたテキストファイル<isbn_code.txt>から所蔵データを取得して,
# カンマ区切りのテキストファイル<rec_data.txt>を出力します.
# --- プログラムの利用について ---
# このプログラムは国立国会図書館サーチ(NDL Search)APIを利用します.
# サーバへの過負荷を避けるために,本プログラムの継続的な利用は避けてください.
# NDL Search APIの利用については次のURLを参照してください.
@rniwase
rniwase / twtapi_fav_ex.py
Created September 27, 2017 16:52
Twitter APIを使って指定したIDのツイートを一括でFavoriteする
# Twitter APIを使って指定したIDのツイートを一括でFavoriteする
from requests_oauthlib import OAuth1Session
import json
CK = 'xxxxxxxxxxxxxxxxxxxxxxxxx' # Consumer Key
CS = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # Consumer Secret
AT = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # Access Token
AS = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # Accesss Token Secert
@rniwase
rniwase / convolution_reverb.py
Created March 2, 2019 23:43
畳み込みリバーブ
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
import soundfile as sf
indata, infrq = sf.read("indata.wav")
impulse, impfrq = sf.read("impulse.wav")
outdata_0 = signal.convolve(indata[:, 0], impulse[:, 0], mode="full")
outdata_1 = signal.convolve(indata[:, 1], impulse[:, 1], mode="full")
@rniwase
rniwase / ht_fdm.py
Created March 2, 2019 23:48
差分法(陽解法,陰解法,Crank-Nicolson法)による1次元非定常伝熱解析
#!/usr/bin/env python
# coding: utf-8
# 差分法(陽解法,陰解法,Crank-Nicolson法)による1次元非定常伝熱解析
import numpy as np
from numpy import matlib
from numpy import linalg
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
@rniwase
rniwase / pyamen.py
Created March 2, 2019 23:53
自動でアーメンを刻むスクリプト、ループ・逆再生・トランスポーズ・タイムストレッチ・エンベロープ・ビットリダクションエフェクト付き
import os
import sys
import wave
import numpy as np
in_file = "amenbrother.wav" # 入力ファイル
out_filename_detail = True # 出力ファイル名にパラメータをつける
in_bar = 1 # 入力データの小節数
out_bar = 8 # 出力データの小節数