フィルターのクリア

Why am I unable to produce sound with this code?

2 ビュー (過去 30 日間)
Yamini
Yamini 2023 年 11 月 26 日
移動済み: Voss 2023 年 11 月 26 日
I'm working on a project where I'm taking the intensities of an image and mapping them to produce frequencies and return an array of notes that will be used for a "song", but I'm unable to actually hear the pitches and frequencies of my song. I've gone through finding the intensities of my image correctly, and I format it into a histogram so as to show the "score" of the music. I'm getting a noise that sounds like a click for every "note" that is supposed to be heard, but there is no audible frequency when I try to listen to it. I don't know if it's a problem with the range I've chosen for the audible human range, but I'd really like some help if anyone is able to take a look at this! I have this main function and a custom function "mus306NoteFinder.m", so please let me know if there's anything else I should upload to help understand the issue better!
% MAIN FUNCTION WHERE MY CODE IS BEING RUN
audibleMin = 100; % changing min frequency from min frequency for humans (20)
audibleMax = 2500; % changing max frequency from max frequency for humans (200)
% creating matrix for all the notes
notes = histMtx(:,2);
Unrecognized function or variable 'histMtx'.
songLength = length(notes);
% making sure all notes are within audible range
for i = 1:songLength
audibleNote = notes(i);
if ((audibleNote / audibleMin) < 1)
audibleNote = audibleNote * 10;
elseif ((audibleNote / audibleMax) > 1)
audibleNote = audibleNote / 10;
end
notes(i) = audibleNote;
end
for i = 1:songLength
currentNote = notes(i);
% using notefinder from previous project to generate note??
singleNote = mus306NoteFinder(currentNote);
finalNotes(i) = singleNote;
end
fs = 44100;
time = 1;
values = 0:1/fs:time;
for i = 1:songLength
noteSound = sin(2*pi*finalNotes(i)*values);
sound(finalNotes(i), fs)
% pause(1)
end
% CUSTOM FUNCTION TO MATCH THE FREQUENCY TO A PROPER PITCH
function [noteFreq] = mus306NoteFinder(f0)
% NoteFinder custom function for MUS306 project (taken from previous project)
% Input: f0 - frequency to take in from intensity of image
% Output: noteFreq - frequency to output for playable tone as music
m = floor(log2(f0/16.3516)); % octave
n = 12*(log2(f0/16.3615) - m) + 1; % scale degree
nRound = round(n);
noteFreq = 16.3516 * 2^(m + ((nRound - 1) / 12));
end
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 11 月 26 日
We would need histMtx to test with.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2023 年 11 月 26 日
移動済み: Voss 2023 年 11 月 26 日
for i = 1:songLength
noteSound = sin(2*pi*finalNotes(i)*values);
sound(finalNotes(i), fs)
% pause(1)
end
You calculate nodeSound, but you ignore the value. Instead you sound() one single entry from finalNotes
  1 件のコメント
Yamini
Yamini 2023 年 11 月 26 日
移動済み: Voss 2023 年 11 月 26 日
That solved my problem!! I changed that line to sound(noteSound, fs), and I was able to hear all my notes. Thank you so much for debugging!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio Processing Algorithm Design についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by