TA的每日心情 | 奋斗 2024-7-1 22:21 |
|---|
签到天数: 2014 天 [LV.Master]伴坛终老
- 自我介绍
- 数学中国站长
群组: 数学建模培训课堂1 群组: 数学中国美赛辅助报名 群组: Matlab讨论组 群组: 2013认证赛A题讨论群组 群组: 2013认证赛C题讨论群组 |
2#
发表于 2013-11-7 10:11
|只看该作者
|
|邮箱已经成功绑定
使用wavread
% j0 c8 G7 V4 A: A4 _& Y* f' I8 XCreate a WAV file from the example file handel.mat,1 Z$ v9 [( N" [! W T5 {
and read portions of the file back into MATLAB.% Create WAV file in current folder.
3 c ^" n c6 W+ T1 e& u( @load handel.mat; F: ]1 D' L& a* }5 A% x
" |& x' ?6 z8 h8 a
hfile = 'handel.wav';
) B( z! S8 D( Pwavwrite(y, Fs, hfile)
6 R+ P' i4 u/ u( t0 [clear y Fs+ G& Z* Q) B+ P, u0 @* e, M
$ p% S/ d7 K+ n, i) ]% Read the data back into MATLAB, and listen to audio.
' Q1 s/ Y; c5 ?; |[y, Fs, nbits, readinfo] = wavread(hfile);
5 H% G" u! \* F& a5 esound(y, Fs);
5 M8 B& O5 X& k# u) ]4 A0 c2 y$ p4 \. n- D j' f
% Pause before next read and playback operation.8 I7 J# h# g7 y9 ^
duration = numel(y) / Fs;# I7 w7 O0 K) N2 t) j
pause(duration + 2)
% A* V) v! K; A2 b+ n # O; _" L8 J8 R; }
% Read and play only the first 2 seconds." u$ p* w5 N7 M9 x6 ]! @! r7 u
nsamples = 2 * Fs;
# D A/ j& x$ u; I- R: I[y2, Fs] = wavread(hfile, nsamples);
" @% ~5 u' i' x \0 }sound(y2, Fs);
% V# Y o# l: H0 B0 Tpause(4)! s* V1 q4 P, `4 r: L
- k8 ]# J+ |, y+ ^+ d
% Read and play the middle third of the file.- |& w% ?3 u* N \ q
sizeinfo = wavread(hfile, 'size');" N* R9 R# g- J
6 D( B9 p0 r% `3 A w
tot_samples = sizeinfo(1);, o# ^: n, w! X! d
startpos = tot_samples / 3;
8 b( T$ o; r7 qendpos = 2 * startpos;) i2 Q7 k' a/ U( L2 X4 [
3 g( W1 U% ]! y: G2 q[y3, Fs] = wavread(hfile, [startpos endpos]); d* K, r* E+ j2 ?! u; D; B4 k
sound(y3, Fs); |
|