Home
Top.Mail.Ru Yandeks.Metrika
Forum: "Other";
Current archive: 2015.12.20;
Download: [xml.tar.bz2];

Down

Midi 2 Beep Code Find similar branches


Дмитрий С ©   (2015-02-05 18:30) [0]

Has anyone encountered the Midi file converter (one of its tracks) into the code from beep and sleep?



Kilkennycat ©   (2015-02-05 20:13) [1]

drive midi to waf, waf is practically a beep slip



brother ©   (2015-02-05 20:18) [2]

Well, if there are no chords in the track, then why not? I think reading from midi is not difficult to implement, and then everything is simple ...)



Kerk ©   (2015-02-05 20:33) [3]

Beep does not work for a long time ...



Дмитрий С ©   (2015-02-05 22:48) [4]


> Beep does not work for a long time ...

It works in w8.1 for me, it just clicks something. Yes, and I for the microns in the end is necessary.


> brother

I study here on Wick :)



Kilkennycat ©   (2015-02-05 22:50) [5]


> for u in the end is necessary

There pwm is for this purpose. in the vast majority of microns.



Дмитрий С ©   (2015-02-05 23:05) [6]


> Kilkennycat

I will use it) I will debug the algorithm on Windows.



Германн ©   (2015-02-06 01:57) [7]


> Dmitry C © (05.02.15 23: 05) [6]
>
>
> Kilkennycat
>
> I will use it) I am debugging the algorithm on Windows.
>

How can you debug the algorithm without seeing (or rather not hearing) the result?
Debug algorithm on the very PC religion prohibits?



Inovet ©   (2015-02-06 03:22) [8]

Maybe it would be more correct to ask anyone from the musically educated people to name the notes with their durations and pauses between them for this melody? So to speak, in a one-time case. And in it (the one-time case) - upload to any MIDI editor, and tear off from there.



KSergey ©   (2015-02-06 09:29) [9]

And in fact - what kind of task is that? and what is the midi file fee?
This one-time specific midic need to convert or constantly-periodically?



Dimka Maslov ©   (2015-02-06 11:18) [10]


> Kerk © (05.02.15 20: 33) [3]
>
> Beep does not work for a long time ...


It seems I read that it was first removed altogether, and then they made it so that the sound did not go to the internal speaker of the computer, but to the sound card. In this case, the conversion of midi to beep-slip (correct) will actually lead to its reproduction by the “tool” SqrWave without multiple tracks, chords and so on. joy



Дмитрий С ©   (2015-02-06 12:10) [11]

I got the impression that I am from a cannon on a sparrow. I needed one melody (a grasshopper was sitting in the grass) and my musical literacy together with Vika had enough to “transform” it manually. At intervals in the chorus messed up, it seems, but not critical, it sounds normal.

Here's an example:
procedure TForm1.Button1Click (Sender: TObject); const // a b c d e f g h i j k l m // do do # re re # mi fa fa # so so # la la # si 4 do Freqs1: array [0..12] of Integer = (262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523); Song = "4jejejii.ieieijj.jejejii.ieieij..jll8lll4mm8mmm4mljijj.jll8lll4mm8mmm4mmjij ..."; L = 220; var I, J, N: Integer; M: Integer; begin Windows.Beep (1, 2000); // enable sound card (can be removed) M: = 4; for J: = 0 to 4 do for I: = 1 to Length (Song) do begin if Song [I] = "." then begin Windows.Beep (20, (L) * 4 div M); end else if Song [I] in ["1" .. "9"] then begin M: = Ord (Song [I]) - Ord ("0"); end else begin N: = Ord (Song [I]) - Ord ("a"); if N <= 0 then Continue; Windows.Beep (Freqs1 [N-1], L * 4 div M); end; end; end;



Дмитрий С ©   (2015-02-06 12:15) [12]

Damn, now I want this melody for ringtone :) How? :))



SOFT_FOR_YOU ©   (2015-02-06 12:38) [13]

I like it :)



MonoLife ©   (2015-02-06 12:41) [14]

cool I remember a long time ago, on Fox, 2.0 wrote a melody while the engine was running around the screen with wagons :) sorry for the source code on 286 and so it was



Дмитрий С ©   (2015-02-06 13:33) [15]

By the way, an error in the line
Windows.Beep (Freqs1 [N-1], L * 4 div M);
Because of what the whole melody turned out half a tone :)



Dimka Maslov ©   (2015-02-06 14:50) [16]


> Damn, now I want this melody for ringtone :) How? :
>))


This is the place to start. Modern phones quietly reproduce midi files. If not, then you need a midi editor (any, but I advise MidiSoft Studio 95, but it only works on a Windows 98 virtual machine). The melody is played there, recorded with something like SoundForge, recorded in the mp3 pin and happiness comes.



Дмитрий С ©   (2015-02-06 15:00) [17]


> This is where we should start.

Well, it's still not the main task to start with. Collateral.



Inovet ©   (2015-02-06 18:15) [18]

Anyway, Phaemi is cooler
http://www.youtube.com/watch?v=wudqDyxUnnI



Дмитрий С ©   (2015-02-06 18:57) [19]


> Inovet © (06.02.15 18: 15) [18]

Nonsense, some kind of



Inovet ©   (2015-02-06 19:23) [20]

> [19] Dmitry C © (06.02.15 18: 57)
> Some kind of nonsense

Well, do not say, find another synthesizer to do it.



Kilkennycat ©   (2015-02-07 05:13) [21]

I had Faemi ... cool thing!



Дмитрий С ©   (2015-02-08 11:38) [22]

Opening day. Pwm is not suitable for extracting sounds :)



Kilkennycat ©   (2015-02-08 12:04) [23]

The monkey is weak with old eyes;
And at people she heard,
That this evil is not yet so big a hand:
Only it is necessary to get Glasses.
She took out the half-dozen glasses with herself;
Twirls Points and syak:
Then to temyu they will be pressed, then they will be pinched on the tail,
Then they sniff them, then water them;
Points do not work in any way.
"Ugh shit!” She says, “and that fool,
Who listens to all the people of the vrat:
All about points only I lied;
And the good of the hair is not in them. "
The monkey here with vexation and with sadness
About the stone so they were enough,
That only the splashes sparkled.

Unfortunately, it happens with people:
No matter how useful a thing is, prices without knowing it,
The ignoramus about her has a good sense for everything;
And if the ignorant know better,
So he also drives her.

I.A. Krylov. 1812 year.



Kilkennycat ©   (2015-02-08 12:09) [24]

http://www.pic24.ru/doku.php/osa/ref/appendix/quartet



Inovet ©   (2015-02-08 14:45) [25]

> [22] Dmitry C © (08.02.15 11: 38)
> Pwm is not suitable for extracting sounds

Through beep and sleep? In general, yes.



Дмитрий С ©   (2015-02-08 20:44) [26]


> Kilkennycat © (08.02.15 12: 09) [24]

I never dreamed of it.

It seems I understood the principle. I will try to do the same on appmege.



Kilkennycat ©   (2015-02-08 22:24) [27]

you look at it: http://www.pic24.ru/doku.php/osa/articles/vga_game there is a video there. with sound ;)



Inovet ©   (2015-02-08 23:10) [28]

> [27] Kilkennycat © (08.02.15 22: 24)
> http://www.pic24.ru/doku.php/osa/articles/vga_game

Cool.



Kilkennycat ©   (2015-02-09 00:13) [29]


> Inovet © (08.02.15 23: 10) [28]

I really like the design of Viktor Timofeev, and how it was done, and the style of description. Very professional and original.



кгшзх ©   (2015-02-09 10:47) [30]

http://www.youtube.com/watch?v=mBfovjFbNMU



brother ©   (2015-02-09 11:07) [31]

http://www.youtube.com/watch?feature=player_detailpage&v=ntYL_uKkblQ
cooler



brother ©   (2015-02-09 11:13) [32]

and classics of the genre
http://www.youtube.com/watch?v=B_Q6jMUdfYc



Дмитрий С ©   (2015-02-09 11:26) [33]


> Kilkennycat ©

Do I understand correctly that you can’t play such a melody on a piezoelectric device?



Kilkennycat ©   (2015-02-09 13:37) [34]

wrong. Anything can be played, even if a piezo squeaker with a built-in generator, changing the supply voltage.



Дмитрий С ©   (2015-02-09 16:53) [35]


> Kilkennycat ©

And how can she give a sinusoid?

Windows.Beep (440) gives a rather pleasant hearing tone on the laptop. Piezopischalka - vile, besides, and not stable (perhaps because of an error in the firmware, I checked the usual Arduinovskim tone).



Kilkennycat ©   (2015-02-09 17:08) [36]


> Dmitry C © (09.02.15 16: 53) [35]

A piezo squeaker can give a sine wave easily, if it is large enough, and lies between the sine waves.

but in its usual application it can produce some electrical force during its deformation, and vice versa: to deform when some electrical force is applied to it, creating air oscillations. Air oscillations are hardly sinusoidal.
theoretically, probably, it is possible to produce a sine wave without a press, if the plate is long enough - to cause a resonance in it.


> ordinary arduinovsky tone

for me it is unusual.

in general, it is difficult to advise something without a complete picture. Here I have a handful of pieziscopters, and electromagnetic speakers of every type. For myself, I see no difficulty in replacing one with the other, or adding to the piezo squeaker some kind of camera body that improves the sound. In addition, for myself, I do not see the need to emulate something on Windows, knowing that this will not be the case at all.
And I am programming almost natively, so I do not know Arduinov blanks.

If you say what you need, I will tell you how to do it.



Дмитрий С ©   (2015-02-09 17:26) [37]


> Kilkennycat © (09.02.15 17: 08) [36]

I do something like a music box. The melody + 3 RGB of the diode to the music changes colors with a short fade effect (and maybe without it, if it slows down), and after the melody - a smoother fade effect (nightlight mode).

I already unsubscribed the payment and checked it. It remains to make the firmware.
I'm going to do the same without arduinovskih blanks. With the help of timers and PWM.



Дмитрий С ©   (2015-02-09 17:29) [38]


> Kilkennycat © (09.02.15 17: 08) [36]

And I plan to take the bass and violin from your example. I'll train at the same time. Instead of a pischilka I will put a small speaker (I will take it from a broken mobile) and a filter as in the diagram from the example.



Дмитрий С ©   (2015-02-09 17:34) [39]

Advise whether it is worth soldering quartz and getting 16 MHz or 8 and will be enough for this task?



brother ©   (2015-02-09 18:14) [40]

[37] I would like to look at the finished device ...



Дмитрий С ©   (2015-02-09 18:17) [41]


> brother © (09.02.15 18: 14) [40]

How will the video lay out.



Kilkennycat ©   (2015-02-09 18:52) [42]


> Is it worth soldering quartz and getting 16 MHz or 8 and will be enough
> for this task?


for this task, the internal generator would be enough, there is more a question of power consumption ... if battery-powered, try to reduce the frequency and get rid of quartz.
in the case of a battery, LEDs are necessarily a shim; will light without shima).
About the tweeter: the speaker, of course, more pleasant. but will eat more, which again is undesirable with battery power.



Inovet ©   (2015-02-10 03:05) [43]

> [35] Dmitry C © (09.02.15 16: 53)
> And how can it sine wave

Real Jedi write "Sinusoyda" and add "ja" for a full passvord, and especially advanced in the art of inhalation know the secret word "Rastafari".



Дмитрий С ©   (2015-02-10 23:19) [44]

While something does not come out: (

Set the timer in PWM mode at a frequency of approximately 15KHz (8 bit timer in two passes at the frequency of the generator 8MHz. 8000000 / 512 = 15625).
I hung up an interrupt on overflowing the counter of this timer itself (it is executed once in 512 processor cycles), where I update the comparison register of the shima (1 times during the 8 timer operations):
tickCount ++; OCR1A = sinCache [(tickCount >> 3)% sizeof (sinCache)]; // (tickCount div 8) mod sizeof (sinCache);
Where:
volatile byte sinCache [64]; for (int i = 0; i <sizeof (sinCache); i ++) { sinCache [i] = 127 + round (127 * sin (6.283 * 440 * i / 1962)); // sin (2 * pi * 440 * i / 1962). 1962 = 15625 / 8 }
The sound turns out vseravno merzsky and even next to it is not necessary with the frequency 440 Hz.



Kilkennycat ©   (2015-02-10 23:40) [45]

Is this MK accidentally not st7fox?



Дмитрий С ©   (2015-02-10 23:48) [46]


> Kilkennycat © (10.02.15 23: 40) [45]

Not. Atmega328, extracted from the arduine-like card.



Kilkennycat ©   (2015-02-11 00:14) [47]

It’s strange that I didn’t guess, because there were so few options ...
what do you think, is there any difference between microcontrollers, their compilers, configuration?
and what is expressed merzsky and even next not worth it with a frequency of 440 Hz.?
what frequency gives out?



Дмитрий С ©   (2015-02-11 00:40) [48]

I will not say for sure, but much higher. Feeling that presses on the ears.
There is a lower sound with a walking frequency.

I am not so deeply familiar with programming mk. I disabled all interrupts except my own, and did not use Arduin functions in its handler.
This is what was in my power :)

I searched in YouTube for melodies on Arduino. - almost everywhere the usual squeak (on / off pin with a given frequency). In one place I saw an idea that might work: to generate voltage not with the help of pwm, but with the help of 8 MK legs and heaps of resistors. In this case, I believe, it is possible to significantly increase the sampling rate. Although I'm certainly not sure what the problem is.



Kilkennycat ©   (2015-02-11 00:47) [49]


> 8 foot MK and heaps of resistors

This primitive DAC


> I am not so deeply familiar with programming mk.

It's clear.
But here the whole problem, as in the questions on Delphi: you do not give information.
In your case, besides all the code (including header files, configs and info about the compiler, including compilation modes), you also need to be informed about the hardware implementation, maybe you hung up on the port FIG know what air conditioner and rezyuk, or maybe through the bridge, is unknown to anyone.



RWolf ©   (2015-02-11 01:01) [50]

Solder some YM2149F and unload into it any of the stats of Spectrum ChipTuns.



Inovet ©   (2015-02-11 01:20) [51]

Is your 15625 an intermittent frequency? Is this a PWM 8 bit? Then
15625 / 256 is approximately 61 Hz. Where did 440 come from?



Kilkennycat ©   (2015-02-11 02:20) [52]


> Where did 440 come from?

four-thread included prescalernaya. no data, useless guessing. 3 of pvm mode, which one is unclear. 8 or 16 bits - only from the words, initialization is invisible. looking for information on YouTube ...



Дмитрий С ©   (2015-02-11 12:32) [53]

It is time to tell more.

Now I want to make two-part polyphony with chord support (since they are in the melody I have chosen).

I was really looking for examples in YouTube, to be sure that this can be done on my MK.

MK I have the following: Atmega328P-PU with Arduinovsky bootloader. IDE: Arduino too. GCC compiler in it. There are no third-party libraries.

I did not solder the quartz, and with the help of fuse bits I turned on the 8MHz generator built into the chip. I did it for a long time and do not remember how.

The connection scheme is as follows: one leg of the speaker is soldered to the PB4 foot, the other through the 120 Ohm resistor (brown, red, brown) to PB1 (because the output of the selected timer and PWM is on it). I also soldered the 0,1 MF capacitor to the speaker contacts (this is http://neoviservis.narod.ru/images/cap_k10_17_104.jpg).
The speaker is pulled from a cheap Nokia (it consists of a film, a coil and a magnet).
On the leg of PB4, I serve just a minus. On foot PB1 - PWM singal.

Instead of a minus in PB4, there was an idea to solder to another PWM output of the same timer (PB2) in order to increase the bit depth of the stream by 1 bits and increase the amplitude of oscillations by switching on the shims one by one. But so far it has not reached.

The sketch is as follows:
volatile unsigned long tickCount = 0; volatile byte sinCache [1024]; void setup () { Serial.begin (9600); // http://www.jameco.com/Jameco/workshop/JamecoBuilds/arduinocircuit_fig12.jpg pinMode (9, OUTPUT); // PB1 foot mode (so for PWM) pinMode (12, OUTPUT); // PB4 foot mode digitalWrite (12, 0); // Minus on PB4 for (int i = 0; i <sizeof (sinCache); i ++) { sinCache [i] = 127 + round (127 * sin (2 * 3.1415926 * 440 * i / 15700)); Serial.print (i); Serial.print (""); Serial.println (sinCache [i]); } // Uninverted | Shim 8 bit http://www.gaw.ru/html.cgi/txt/doc/micros/avr/arh/mega103_38.htm // and http://www.gaw.ru/html.cgi/txt/doc/micros/avr/arh/mega103_43.htm TCCR1A = (1 << 7) | (1 << 0); // http://www.gaw.ru/html.cgi/txt/doc/micros/avr/arh/mega103_39.htm TCCR1B = (1 << 0); // Without frequency divider SREG | = (1 << 7); // Global interrupt resolution. TIMSK1 = (1 << TOIE1); // Allow T1 overflow interrupt. (the rest are off) // For diagnostics, it does not matter: unsigned long predTickCount = tickCount; while (1) { Serial.print (OCR1A); Serial.print (""); Serial.print (tickCount); Serial.print (""); Serial.println (tickCount - predTickCount); predTickCount = tickCount; delay (1000); } } ISR (TIMER1_OVF_vect) { tickCount ++; // http://www.gaw.ru/html.cgi/txt/doc/micros/avr/arh/mega103_43.htm OCR1A = sinCache [(tickCount)% sizeof (sinCache)]; } void loop () { }

I can record the result in the evening.


> Inovet © (11.02.15 01: 20) [51]
> Is your 15625 the frequency of the interruptions? Is this a PWM 8 bit?
> Then
> 15625 / 256 approximately 61 Hz. Where did 440 come from?

15625 once a second, the timer has time to go from 0 to 255 and then to 0.
440 is formed by forming a sine wave by changing the width of the PWM.



Kilkennycat ©   (2015-02-11 13:19) [54]


> The connection scheme is as follows: one leg of the speaker is soldered to the foot
> PB4, the other through the resistor 120 Ohm (brown, red, brown) to
> PB1 (because the output of the selected timer and PWM is on it).
> Just to the contacts of the speaker, I soldered the capacitor 0,1 mkf

that is, if you mess up with the initial state of the port u, you reach the current in 40 milliamperes. Soon go buy a new percent.



RWolf ©   (2015-02-11 13:40) [55]

Well, that is, the PWM frequency 15625 / 2 = 7.8125 kHz?
To get an estimate of the upper limit of the signal frequencies, divide by 4. A dirty sound will come out.



Дмитрий С ©   (2015-02-11 13:42) [56]


> that is, if you mess up with the initial state of the port u,
> you reach the current in 40 milliamps. Soon go buy
> new percent

Hardly. Firstly, the speaker also has resistance, albeit slight. Secondly, I'm debugging on 3,3 B, and in the end it will work from 4,5 B (three batteries for 1,5 B). Therefore, the current will not exceed 40 mA and will always be valid.



Inovet ©   (2015-02-11 13:43) [57]

Those. You proceeded from the assumption of the dynamics of the resistance more kiloom, something seems to me that its resistance is several tens of Ohms, Ohm 32. I did not understand the bit about the increase in bit depth on 1, all the more I did not understand about the increase in amplitude. Okay. Your speaker reproduces these your 15625 Hz with the corresponding artifacts. The low-pass filter should be tuned lower, and the amplifier should be done, at least on one transistor.



Дмитрий С ©   (2015-02-11 13:47) [58]


> Well, that is, the PWM frequency 15625 / 2 = 7.8125 kHz?
> To obtain an estimate of the upper frequency limit of the signal, divide
> more on 4. A dirty sound will come out.

Why divide by two?
15625, and in fact it turns out 15700, this is roughly the number of minima in the figure:
http://www.gaw.ru/im/_micros/avr/arh/34.gif
those. this is the frequency of shima.

Is it possible in more detail about the "divide more by 4"?



Дмитрий С ©   (2015-02-11 13:51) [59]


> Inovet © (11.02.15 13: 43) [57]

I started from the item "Second" from [56].

3,3 V / 120 Ohm = 27,5 mA (with valid 50)
4,5 V / 120 Ohm = 37,5 mA (with a valid more than 40)

What does it mean "low pass filter should be configured below"?

The amplifier will do as I get a normal sound without it.



Inovet ©   (2015-02-11 13:53) [60]

> [59] Dmitry C © (11.02.15 13: 51)
> What does "low pass filter need to set up below"?

Are you the condenser on the 0,1 microfarad from the lamp soldered?

> [59] Dmitry C © (11.02.15 13: 51)
> I will make the amplifier, as I will receive a normal sound without it.

Money in the morning, evening chairs.



Inovet ©   (2015-02-11 13:55) [61]

This is if we assume that everything is done correctly in the program, and on the output we really wake up that sinusoid on 440 Hz, and not some garbage.



RWolf ©   (2015-02-11 13:59) [62]


> Why divide by two? 15625, and in fact it turns out 15700,

That's right, I already read above.


> Is it possible in more detail about the "divide more by 4"?

Well, they taught me this: tune the low-pass filter to a quarter of the PWM frequency so that the useful signal in the ring does not sink.



Дмитрий С ©   (2015-02-11 14:05) [63]

Regarding the increase in bit depth and amplitude, these are my thoughts:

We have two 8-bit PWM outputs, we connect a speaker to them, let's call them A and B.

Next, we form the 9-bit signal: from -255 to 255. Let the value of the signal at the considered time t: S (t).

The speaker is positioned so that its diaphragm moves up and down.

Consider a few situations:

1. S (t) = 0. On legs A and B, 0 or 1 are simultaneously fed. The diaphragm is in a neutral position.
2. S (t) = 200 (i.e.> 0). 0 is fed to leg B, and the PWM signal 200 / 255 is fed to leg A. The diaphragm is above the neutral position at 200 / 255 from the limit.
3. S (t) = -200 (i.e. <0). 0 is fed to A's leg, and the 200 / 255 PWM signal is fed to B's leg.
The diaphragm is below the neutral position at 200 / 255 from the limit.

------------------------

While writing, I came up with another version with one PWM. Suppose that leg A is PWM and B is regular 0 / 1.

Consider a few situations:
1. S (t) = 0. On legs A and B, 0 or 1 are simultaneously fed. The diaphragm is in a neutral position.
2. S (t) = 200 (i.e.> 0). On A - PWM signal 200 / 255, on B - 0. The diaphragm is above the neutral position at 200 / 255 from the limit.
3. S (t) = -200 (i.e. <0). On A - PWM (255-200) / 255, on leg B - 1. The diaphragm is below the neutral position at 200 / 255 from the limit.

As a result, we find that the speaker diaphragm does not move from 0 to 1, but from -1 to 1 (the amplitude is doubled), and the signal is 9 bit (-255 to 255).



Kilkennycat ©   (2015-02-11 14:09) [64]


> Therefore, the current will not exceed 40 mA and will always be valid.

wrong.
Firstly, even with 3.3 c. current over xnum ma.
with 4.5 you are close to the maximum consumption value.
Let me remind you that the maximum is not equal to the nominal one.
Well, the implementation of the bridge on two legs ... at the time of switching can get out.



Дмитрий С ©   (2015-02-11 14:10) [65]


> Are you the condenser on the 0,1 microfarad from the lamp soldered?

Practically.
In general, from here http://www.pic24.ru/doku.php/osa/ref/appendix/quartet


> Well, they taught me that

I correctly understood, the sampling frequency of the sound itself is at least 4 times smaller than the PWM frequency, should it be?
On the waveOut I checked that the sampling frequency of the very sound 1,96 kHz is enough for me, so I even have a margin.

var WF: tWAVEFORMATEX; WaveOutHandle: HWAVEOUT; i: Integer; Buf: array [0..3 * 8000-1] of byte; H: TWaveHdr; begin wf.cbSize: = SizeOf (wf); wf.wFormatTag: = WAVE_FORMAT_PCM; wf.nChannels: = 1; // 1 channel wf.wBitsPerSample: = 8; // 8 bit wf.nBlockAlign: = (wf.nChannels * wf.wBitsPerSample) div 8; wf.nSamplesPerSec: = 1960; // 1,96 kHz wf.nAvgBytesPerSec: = wf.nSamplesPerSec * wf.nBlockAlign; Winapi.Windows.Beep (880, 2000); for I: = 0 to Length (Buf) - 1 do begin if I <8000 then Buf [I]: = (127 + Round (127 * (Sin (2 * Pi * I * 880 / wf.nSamplesPerSec)))) else if I <16000 then Buf [I]: = (127 + Round (127 * (Sin (2 * Pi * I * 440 / wf.nSamplesPerSec)))) else Buf [I]: = (127 + Round (127 * (Sin (2 * Pi * I * 440 / wf.nSamplesPerSec) + Sin (2 * Pi * I * 880 / wf.nSamplesPerSec)) / 2)); end; ZeroMemory (@H, SizeOf (H)); H.lpData: = PAnsiChar (@Buf); H.dwBufferLength: = SizeOf (Buf); H.dwBytesRecorded: = 0; H.dwFlags: = WHDR_INQUEUE; H.dwLoops: = 10; waveOutOpen (@WaveOutHandle, WAVE_MAPPER, @wf, 0, 0, WAVE_ALLOWSYNC or CALLBACK_NULL); waveOutPrepareHeader (WaveOutHandle, @H, sizeof (H)); waveOutWrite (WaveOutHandle, @ H, sizeof (H)); waveOutReStart (WaveOutHandle); end;



Дмитрий С ©   (2015-02-11 14:14) [66]


> wrong.
> firstly, even with 3.3 c. current over xnum ma.
> with 4.5 you are close to the maximum consumption value.
>
> I recall that the maximum is not equal to the nominal.
> well, the implementation of the bridge on two legs ...
> at the time of switching
quoted1>> Kaka can come out.


There, in any case, the PWM signal - even outside of this current - is unlikely that the MC will be damaged. And with 3.3 V, the permissible current - 50 mA - is from the description of the MC.

And you still need to get to "Kaki" :) Given that there will be outputs on one port, they will switch at the same time practically. I do not know, however, how the condenser will be from this :) But, I repeat, it is still necessary to walk to this.



Inovet ©   (2015-02-11 14:16) [67]

> [65] Dmitry C © (11.02.15 14: 10)
> Practically.
> In general, from here

Well, how much is written there? 78 kHz, and you have 15 kHz.



Дмитрий С ©   (2015-02-11 14:17) [68]


> Well, how much is written there? 78 kHz, and you have 15 kHz.

If you want to help, help, and this I myself see: (



Inovet ©   (2015-02-11 14:24) [69]

> [68] Dmitry C © (11.02.15 14: 17)

On 78, the speaker itself will add filtering, because it will not reproduce this frequency and will average it. And 15 reproduces well enough, it is necessary to filter more, increase the capacitance of the capacitor to 0,5 microfarad.



Дмитрий С ©   (2015-02-11 14:32) [70]

While I have an idea: to increase the frequency of SHIM.

And the following ideas:
1. To make the formation of a PWM signal manually with a period of 128, instead of 512, thereby increasing the frequency 4 times, to about 62 kHz. By sacrificing the sound band's 1 bit.

2. Solder quartz to 16 or 20 MHz. For 8-bit shima, we get: 20MHz / 256 = 78 KHz is better.

Interestingly: is it possible to switch * on the move * between the outer quartz and the internal generator?



Kilkennycat ©   (2015-02-11 14:45) [71]


> There's a PWM signal anyway — even outside of that
> current - it is unlikely that the MC will deteriorate. And with 3.3 V valid
> current - 50 mA

not in any way. There are three cases where he will not be there. at the moment of inclusion, at failure-freezing and at an error.
and there is not valid, and the maximum. work at the maximum is not guaranteed; one micron will fall - it will work for a long time, the other will die immediately.
and where did you see 50 in datasheet? there is 40. And you said that 3.3 is debugging, and working with 4.5 is somehow strange, usually debugged-tested in a working or more extreme mode, but on the contrary


> but you can switch * on the go * between the outer quartz and
> internal generator?


read datashit. everything is there.



RWolf ©   (2015-02-11 15:24) [72]


> Dmitry C © (11.02.15 14: 32) [70]
> While I have an idea: increase the frequency of SHIM. And the following ideas:
> quartz on 16 or 20 MHz.

There is a special mega with an integrated PWM frequency multiplier.



Kilkennycat ©   (2015-02-11 16:13) [73]


> 2. Solder quartz to 16 or 20 MHz. For 8-bit shima, we get:
> 20MHz / 256 = 78 KHz is better.

I can on your atmega with the internal 8 MHz generator get the maximum 4 MHz clock ... just read the datasheet. also have to underestimate.


> 20MHz / 256 = 78 KHz is better.

The formula is incorrect. In the datasheet a different calculation.



Дмитрий С ©   (2015-02-11 16:35) [74]


> I can get on your Atmega when the internal generator of 8 MHz
> max 4 MHz max ... just read datashit. also underestimate
> have to.

So I want to make software. Set the timer to normal mode. And in the interrupt when the timer reaches a certain value, update the timer settings so that we get 128 cycles of time, instead of 512, which is minimal hardware.

Although, of course, in extreme positions the handler will not have enough time to execute.

It turns out that this MK is unable to do what I want from it?



RWolf ©   (2015-02-11 16:40) [75]

What Fast PWM didn’t please?



Дмитрий С ©   (2015-02-11 16:55) [76]


> RWolf © (11.02.15 16: 40) [75]

He began to look for what it is and found a cool article, just on a similar topic.

http://easyelectronics.ru/avr-uchebnyj-kurs-ispolzovanie-shim.html

Thank you.

PS Who-thread knows places in Moscow, where you can come to work with it all and where there will be equipment (soldering iron, oscilloscope) and perhaps an adviser :)



Kilkennycat ©   (2015-02-11 17:53) [77]


> So I want to make a software shim.

what for? There is a wonderful hardware, and not one, you can zapabahat polyphony. less effort. and you want a software .... developing the idea further, you and the MK will not be needed - several resistors, an ID counter, one LA3 and an operational amplifier.



RWolf ©   (2015-02-11 17:57) [78]


> [77]

There are wonderful hardware music processors for mere pennies. All this fussing with shims is not worth home use; I understand, if in a serial device - there it is necessary to save.



Дмитрий С ©   (2015-02-11 18:49) [79]


> Kilkennycat © (11.02.15 17: 53) [77]

The hardware frequency is too small.


> RWolf © (11.02.15 17: 57) [78]

Well, it's too late, the device has already been assembled. And the idea of ​​"forgetting" polyphony came after I had collected it.



Kilkennycat ©   (2015-02-11 20:17) [80]


> The hardware frequency is too small.

not at all ... you just don't feel it.
Think about it yourself - what is the reason for having a hardware shima? Are the developers really underestimated its frequency response, to which there are no prerequisites, for the sake of anything? Think objectively that the developers of the micron are somewhat stronger than you and me together (and this is so), and the impossibility of extracting the right sound is not their joint, but ours.
try to realize shim that it is not only frequency, i.e. the ratio of the period to the unit, but also the duty ratio and duration, that there are many modes of sym, which allow you to simulate to some extent the modulation and modulation, there such sounds can be extracted, which is just horror. The whole thing is precisely in the realization of how it works.
otherwise, it is easier to spend 3 * N + 1 resistors and assemble a primitive DAC and drive 8 (16) -bit wav



Inovet ©   (2015-02-11 20:32) [81]

> [80] Kilkennycat © (11.02.15 20: 17)
> 8 (16) -bit wav

On 16, you need exact resistors and the rest too.



Kilkennycat ©   (2015-02-11 20:35) [82]


> Inovet © (11.02.15 20: 32) [81]

Well, the bit on the accuracy does not soon begin to affect, if the error of the resistors do not have time to overlap. 5% is also possible if high resistances are acceptable



Inovet ©   (2015-02-11 20:36) [83]

take a kilometer of wire, cut off a piece of 0,01 m, solder it, then 0,02 m, solder it and end it with a piece of 655,36 m. With frequency, only problems will arise.



Inovet ©   (2015-02-11 20:38) [84]

> [82] Kilkennycat © (11.02.15 20: 35)
> you can and 5%

Well, you can cut the same pieces, but with an accuracy of 0,001%.



Inovet ©   (2015-02-11 21:09) [85]

Deleted by moderator



Дмитрий С ©   (2015-02-12 13:32) [86]

Yesterday we managed to get the PWM frequency in 80 KHz in the Fast PWM mode, by a large number of samples. And I read datashit, surprisingly, a document that is understandable to me.

As a result, there were even hints of the sound that I want to receive. True all 6,6 bits, if you count. An oscilloscope is coming over the weekend - I think debugging will be more fun with it.



Дмитрий С ©   (2015-02-14 21:50) [87]

It seems to have received a normal sound, but very quiet. Guys, tell me how to make a simple amplifier on a transistor?



Kilkennycat ©   (2015-02-14 23:57) [88]

ГУГЛ



Дмитрий С ©   (2015-02-15 13:00) [89]


> Kilkennycat © (14.02.15 23: 57) [88]

This is also true, but knowledge alone is not enough, and more experience is needed.

In general, I collected a simple amplifier + I also plugged a capacitor on the 10 microfarad between the base of the transistor and the ground - the sound became much better. I think I'll have to pick it up.

Now here's the big question, and how to connect the two frequencies? Those. There are two signals, how to get out of the combined?



Kilkennycat ©   (2015-02-15 13:34) [90]

google mixer



RWolf ©   (2015-02-15 18:18) [91]

what to interfere with? In this apparatus, two shima, or what?



Inovet ©   (2015-02-15 18:58) [92]

> [91] RWolf © (15.02.15 18: 18)
> in this device two shima, or what?

See, not mastered software mixing.



Дмитрий С ©   (2015-02-15 18:58) [93]


> RWolf © (15.02.15 18: 18) [91]

No, shim1. Programmatically mix the two frequencies.

There is a 8-bit sinusoidal sound signal (always positive) with a frequency of 440 Hz. The S1 (x) function returns the value of this signal, where X is the sampling step.
Accordingly, S1 (x) can take values ​​from 0 to 255.

There is a similar signal, but by frequency, for example, 523 Hz, its function is S2 (x).

And there is an 8-bit OUT register, where I put the signal value (total) of each sampling step.

With one signal (one frequency), everything worked out as it should be: a sufficient sound quality is obtained (acceptable for me, taking into account the amplifier and the filter).

But with two it is not at all clear how to summarize them.
There are chords in the melody chosen by me and it is required to play up to 4 signals simultaneously.
Average arithmetic perhaps? In this case, I am confused by the fact that one signal will be quieter to play in 4, while the others are silent.

At the moment I have achieved the following indicators:
The speed of 8-bit PWM and 31250 Hz. (can be increased by the bitness of the shima).
The sampling rate is 7812 Hz. (can be increased to about 15 kHz).



Kilkennycat ©   (2015-02-15 19:07) [94]

and I would just take ARM Cortex M3 and forget about x3 playback. In a day.



Inovet ©   (2015-02-15 19:10) [95]

> [93] Dmitry C © (15.02.15 18: 58)
> that one signal will be quieter in 4 to play while the others are silent.

And should it be the same? those. four notes or even instruments all together with the maximum level are heard, then the three become silent and suddenly the rest starts to sound louder, like all four together before that. An interesting approach. Bear in mind that the changes in the level of sound will be perceived by the hearing quite differently from what you think.



Inovet ©   (2015-02-15 19:14) [96]

And about mixing. Just add them and everything, only in the recording of notes, except for the note number and duration, you must still maintain a level, or at least for each batch, common to all notes.



Дмитрий С ©   (2015-02-15 19:20) [97]


> Inovet © (15.02.15 19: 14) [96]

Those. add and divide by their quantity, right?

I analyzed the project of the quartet, previously mentioned in the branch. There it seems so done.



Inovet ©   (2015-02-15 19:24) [98]

> [97] Dmitry C © (15.02.15 19: 20)
> Ie add and divide by their quantity, right?

On the move, I wouldn’t divide, it would be better in advance when debugging, or how can I call this process - mixing, aha, I donated everything once so that it sounded normal, and when I played it I just added it.



Kilkennycat ©   (2015-02-15 19:25) [99]


> Ie add and divide by their quantity, right?

Do you understand the difference between duty cycle, duration and amplitude? mixing two frequencies does not change the amplitude, so why should the instrument sound quieter?



Inovet ©   (2015-02-15 19:28) [100]

> [99] Kilkennycat © (15.02.15 19: 25)

Yes, all right, he says - it will be quieter, it should, but it will not, so it will creep into overflow. But PWM there or another type of modulation is the second.



Дмитрий С ©   (2015-02-16 10:54) [101]


> Kilkennycat © (15.02.15 19: 25) [99]

Let's leave modulation for now, first you need to decide what to modulate.

Here are the graphs of the functions describing 440 Hz and 523 Hz (100 X divisions per second).
Respectively blue and green.

Orange is their sum. It is clearly seen that the amount goes beyond [-1; 1] and it's not difficult to establish that its framework is [-2; 2]. But we have the channel [-1; 1], and accordingly the result should be somehow entered into it.

http://yotx.ru/#!1/2_h/sH@1v7Rgzhf23/aH/zYv9i34gh/K/t/wPhGztgABC8BwaBDra3Dg529w/2STTsxs4p4/F0i/G4dXmxu/8PhG/sgAFA8B74bOdie@vgYHf/YJ9Ew24cMB63Lk4Zjwe7@/9A@MYOGAAE74FBoIPtrYODXeg/EL6xAwYAwXvgs52L7a2Dg939g30SDbuxc3bGeNzaumQ8biF29wEH

There are two options left:
A) divide by 2.
B) find another way to sum up.

Your suggestions?



Дмитрий С ©   (2015-02-16 11:31) [102]

The arithmetic average seems to me the best option.
But questions arise:
And if the frequencies are 4 or 50 and which ones will be strong and which ones will not, + their strength will change with time, then by how much to divide?



Дмитрий С ©   (2015-02-16 12:57) [103]

Having listened to what are the tunes and came to the conclusion that too long the time and the result will be so-so. I decided to go about the path> Kilkennycat © (15.02.15 19: 07) [94].
I solder something like http://amperka.ru/product/df-player-mp3-module, and through ADC I will already “catch” the sound and highlight the flowers of my composition.
It remains only to determine the speaker :)

Thank you all for your patience and advice!



Kilkennycat ©   (2015-02-17 00:08) [104]


> Dmitry C © (16.02.15 12: 57) [103]

Actually, I came to this path by comparing the cost of the controller and the time spent trying to sbatsat something ukhlenky that can make more steep ...
but there is one thing: such attempts are well-trained and often there is a need, when it is nevertheless necessary to be deadly, for example, I bought them a hundred pieces, but the good should not be lost :)



KSergey ©   (2015-02-17 09:22) [105]

> Dmitry C © (05.02.15 18: 30)
> Has anyone encountered the Midi file converter (one of his tracks) in the code from beep and sleep?

But this is selected - it was immediately in the question?
if so - shame on me, did not notice the key point



brother ©   (2015-02-17 11:14) [106]

Yes, you cannot edit messages to the user after sending ...



Дмитрий С ©   (2015-04-30 13:51) [107]

So I scored on polyphony. Made a normal beep.

It turned out this:

http://www.youtube.com/watch?v=aV42lAC04v4



RWolf ©   (2015-04-30 13:58) [108]

Somehow quietly quite, move the microphone closer, or something.
And what are the unknown problems with polyphony, after such a discussion?



Дмитрий С ©   (2015-04-30 14:33) [109]


> RWolf © (30.04.15 13: 58) [108]

I did not achieve acceptable quality in the allotted time. For me, 8 MHz is not enough for polyphony.



Inovet ©   (2015-04-30 14:51) [110]

> [109] Dmitry C © (30.04.15 14: 33)
> For me, 8 MHz is not enough for polyphony.

And as soon as earlier on every 4 MHz i8086, let alone i8080, Z80, etc., they managed to do ...



Inovet ©   (2015-04-30 14:54) [111]

> [107] Dmitry C © (30.04.15 13: 51)
> It turned out this:

Is this something "Katyusha" in jazz processing?



RWolf ©   (2015-04-30 15:05) [112]


> [109]

In one of my hand-made articles on the 14 MHz card, three voices are played without straining. One could add more.



Дмитрий С ©   (2015-04-30 17:31) [113]


> And as soon as earlier on everyones 4 MHz i8086, let alone
> about i8080, Z80, etc., they managed to do ...

Maybe there was a separate sound generator of some kind?
Suppose 8 bit sound.
Somewhere in the branch I read that it is desirable that the PWM have 4 time to count to the end.
256 * 4 = 1024 cycle. With a sampling frequency of 8000Hz, we get the 8192000 cycle per second. Four MHz is clearly not enough. Although 8i can still be played. But it is later, in free time.


> In one of my hand-made articles on the 14 MHz module, three voices are played
> not straining.

Do not make it difficult to show the code? I wonder how I did.



RWolf ©   (2015-04-30 19:50) [114]


> [113]

The code is closed, but all the principles have already been discussed here: timer interrupts with a frequency of 28 kHz, the note is passed through the sine table, the loudness table, the current sound pressure value in the channel is obtained. Repeat for all channels, mix the results, update the PWM control register.



Pages: 1 2 3 whole branch

Forum: "Other";
Current archive: 2015.12.20;
Download: [xml.tar.bz2];

Top





Memory: 1.07 MB
Time: 0.083 c
2-1403689302
Imagination
2014-06-25 13:41
2015.12.20
CopyPaste does not work


15-1429522423
pavelnk
2015-04-20 12:33
2015.12.20
According to Android


15-1429879718
Andy bitoff
2015-04-24 15:48
2015.12.20
VCL controls. Collapsing font.


2-1403717600
Sakipiel
2014-06-25 21:33
2015.12.20
how to add an item to the successor TCollection


2-1403529768
Sakipiel
2014-06-23 17:22
2015.12.20
All events on the same procedure





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic Indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Spanish swahili Swedish ภาษาไทย turkish Ukrainian urdu Tiếng Việt welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada Khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish