Showing posts with label Tutorial Octave. Show all posts
Showing posts with label Tutorial Octave. Show all posts

Monday, November 07, 2011

Play Sound/Audio File such as .wav in GNU / Octave

In octave, there is not function like wavplay or sound such in Matlab. Octave has own function to play audiofile i.e playaudio, but it is never work for me. Instead of repair the playaudio function in Octave, below is simple script function to play sound file in Octave.

Please copy the code below and paste to your PC (work on Ubuntu Linux) as playsound.m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% This function play the singal x as a sound.
% playsound(x, fs, bits)
%  x : a signal vector
%  fs: sampling frequency in Hz
%  bits: quantization bits
%
% If encounter a error, try to transpose a signal vector,
% like playsound(x',fs,bits)

function playsound(x,fs,bits)
if (nargin != 3)
  usage("playsound(x,fs,bits)");
endif

 file= strcat(tmpnam(),".wav");
 wavwrite(file,x,fs,bits); 
 system(sprintf("/usr/bin/paplay %s ; rm -f %s",file,file));
endfunction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Tuesday, October 11, 2011

Menyimpan data .wav/.mat dalam format ASCII di Matlab / Octave

ASCII - American Standard Code for Information Interchange merupakan format standar data yang berupa text yang akan memudahkan kita untuk memprosesnya dalam program dan OS apapun. Nah, bagaimana menyimpan data kita dalam format ASCII ? Caranya adalah dengan menyimpan anda dalam workspace Matlab atau Octave, kemudian simpan sebagai file format ASCII dengan perintah berikut ini. (Mungkin juga berlaku untuk selain data .wav dan .mat, yakni data berekstensi lain .xml dll, sekali lagi load dulu ke workspace-nya matlab/Octave).

Dalam Matlab,
x=wavread('nama_file.wav');                      % load file wav anda

save namafiletxt x -ASCII


jika data anda berupa .mat

load data

save namafiletxt x -ASCII                           % load file mat


Dalam Octave, ganti -ASCII menjadi -ascii, sehingga menjadi sebagai berikut:
Related Posts Plugin for WordPress, Blogger...