Autor Beitrag
Blacked
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Mi 27.07.05 19:46 
Hallo, ich habe folgendes problem.
Ich habe den unten stehenden Code der auch Prima funktioniert.
Die Funktion ist diese das wenn er ausgeführt wird, er einen Ton über die Soundkarte mit gewisser länger und gewisser Hertz zahl ausgibt.
Nun soll er aber nicht einen Ton in den Speicher laden und dann an die Soundkarte schicken sondern 5 oder x und dann erst an die Soundkarte schicken... aber wichtig es müssen 5 verschiedene Töne sein.
Denn wenn ich die Funktion aufrufe...
MakeSound(1000,70); und beim nächsten dann MakeSound(200, 70); usw. dann hat das ganze einen kleinen versatz... deshalb soll er zuerst die einzelnen Töne in den Speicher laden und dann erst an die Soundkarte schicken.
Ich habe den Code nur durch glück gefunden... und weiss jetzt halt nicht weiter wie ich das umschreiben könnte damit es so funktioniert. vielleicht hat je einer eine Idee?!?!
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
procedure MakeSound(Frequency{Hz}, Duration{mSec}: Integer; Volume: TVolumeLevel);
  {writes tone to memory and plays it}
var
  WaveFormatEx: TWaveFormatEx;
  MS: TMemoryStream;
  i, TempInt, DataCount, RiffCount: integer;
  SoundValue: byte;
  w: double; // omega ( 2 * pi * frequency)
const
  Mono: Word = $0001;
  SampleRate: Integer = 11025; // 8000, 11025, 22050, or 44100
  RiffId: string = 'RIFF';
  WaveId: string = 'WAVE';
  FmtId: string = 'fmt ';
  DataId: string = 'data';
begin
  with WaveFormatEx do
  begin
    wFormatTag := WAVE_FORMAT_1M08;
    nChannels := Mono;
    nSamplesPerSec := SampleRate;
    wBitsPerSample := $0008;
    nBlockAlign := (nChannels * wBitsPerSample) div 8;
    nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
    cbSize := 0;
  end;
  MS := TMemoryStream.Create;
  with MS do
  begin
    {Calculate length of sound data and of file data}
    DataCount := (Duration * SampleRate) div 1000; // sound data
    RiffCount := Length(WaveId) + Length(FmtId) + SizeOf(DWORD) +
      SizeOf(TWaveFormatEx) + Length(DataId) + SizeOf(DWORD) + DataCount; // file data
    {write out the wave header}
    Write(RiffId[1], 4); // 'RIFF'
    Write(RiffCount, SizeOf(DWORD)); // file data size
    Write(WaveId[1], Length(WaveId)); // 'WAVE'
    Write(FmtId[1], Length(FmtId)); // 'fmt '
    TempInt := SizeOf(TWaveFormatEx);
    Write(TempInt, SizeOf(DWORD)); // TWaveFormat data size
    Write(WaveFormatEx, SizeOf(TWaveFormatEx)); // WaveFormatEx record
    Write(DataId[1], Length(DataId)); // 'data'
    Write(DataCount, SizeOf(DWORD)); // sound data size
    {calculate and write out the tone signal} // now the data values
    w := 2 * Pi * Frequency; // omega
    for i := 0 to DataCount - 1 do
    begin
      SoundValue := 127 + trunc(Volume * sin(i * w / SampleRate)); // wt = w * i / SampleRate
      Write(SoundValue, SizeOf(Byte));
    end;
    {now play the sound}
    sndPlaySound(MS.Memory, SND_MEMORY or SND_SYNC);
    MS.Free;
  end;
end;


PS: ES soll wenn es fertig ist so funktionieren wie das Folgetonprogramm (falls das jemand kennt?!?)
www.funkmeldesystem....ownload/ag32_win.zip
Ich hoffe auf euere Hilfe.
Danke.

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.

_________________
Modern programming is a race between the programmer striving to build bigger and better idiotproof programs and the Universe trying to build bigger and better idiots.
So far the Universe is winning.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 27.07.05 20:04 
Du reservierst Dir einfach in deinem Puffe den Platz für alle Töne, die ausgegeben werden sollen. Danach generierst Du Dir die fünf verschiedenen Frequenzen und schreibst in den Puffer hintereinander weg gleich deine verschiedenen Töne.

(Am besten unter Beachtung der Phasenverschiebung.)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Blacked Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Do 28.07.05 08:07 
Genau das ist das Problem. Wie mache ich das? Das ich den Puffer mit den 5 Tönen fülle?
Ich habe leider nicht das "Know How" um das anhand des bestehendes Quellcodes umzuschreiben. Könntet ihr vielleicht ein beispiel Posten wie das gehen könnte?!
:(
Danke.
Gruß

_________________
Modern programming is a race between the programmer striving to build bigger and better idiotproof programs and the Universe trying to build bigger and better idiots.
So far the Universe is winning.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 28.07.05 11:18 
DataCount --> Gesamtlänge

L1-L5 --> Teillängen der Töne, ergeben zusammen DataCount

Zeile 46-50: Für folgende Bereiche wiederholen:

ausblenden Quelltext
1:
2:
3:
4:
5:
0 --> L1-1
L1 --> L1 + L2-1
L1 + L2 --> L1 + L2 + L3-1
L1 + L2 + L3 --> L1 + L2 + L3 + L4-1
L1 + L2 + L3 + L4 --> L1 + L2 + L3 + L4 + L5-1


Dabei zwischen jeder Schleife die Frequenz in W entsprechend anpassen

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Blacked Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Do 28.07.05 16:32 
Was meinst du genau mit diesem:

0 --> L1-1
L1 --> L1 + L2-1
L1 + L2 --> L1 + L2 + L3-1
L1 + L2 + L3 --> L1 + L2 + L3 + L4-1
L1 + L2 + L3 + L4 --> L1 + L2 + L3 + L4 + L5-1

Ich habe jetzt zwar verstanden wie du das meinst... und ich denke ich kann das auch umsetzen...

Ich mache am besten die "w" berechnung mit in die For-Schleife... allerdings weiss ich nicht was du mit dem o.g. meinst?! Und vorher Reserviere ich mir natürlich den Platz für meine Fünf Töne. (In DataCount)
Nur jetzt die Frage, reicht es wenn ich nur w ändere damit es dann 5 verschiedene Töne sind... woher was der dann er nicht der ersten Ton im Speicher überschreibt usw usw. also quasi der er immer von vorne in den Speicher schreibt und nicht den Ton 2 an den Ton1 hängt und den Ton3 an Ton2 usw.?!

Oder verstehe ich da jetzt etwas falsch?!
*binhalteinwenigverzweifelt* *sorry*
:oops:

_________________
Modern programming is a race between the programmer striving to build bigger and better idiotproof programs and the Universe trying to build bigger and better idiots.
So far the Universe is winning.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 29.07.05 16:07 
Falls ich chinesisch rede, würde ich Dir den Besuch eines Deutschkurses empfehlen.

Die genannten 5 Zeilen sind die Teilbereiche in der Wave-Datei (wie es auch schon in meinem vorherigen Post drin stand).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Blacked Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30



BeitragVerfasst: Fr 29.07.05 16:48 
user profile iconBenBE hat folgendes geschrieben:
Falls ich chinesisch rede, würde ich Dir den Besuch eines Deutschkurses empfehlen.

Die genannten 5 Zeilen sind die Teilbereiche in der Wave-Datei (wie es auch schon in meinem vorherigen Post drin stand).


Sorry, wenn ich hier eine Frage poste... musst ja nicht drauf antworten. Aber dann gleich so gereizt zu reagieren ist auch nicht nötig.

Ich wollte nur wissen was es mit den Bezeichnungen auf sich hat 0 -> L1 z.B. heisst das dann 0 = L1 ? oder wie ist das zu verstehen?

Nun denn.
Danke trotzdem.
Ich versuche es mal weiter.

Gruß Björn

PS: Sorry nochmal.

_________________
Modern programming is a race between the programmer striving to build bigger and better idiotproof programs and the Universe trying to build bigger and better idiots.
So far the Universe is winning.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 29.07.05 16:52 
0 --> L1-1 hieß Von 0 bis L1-1 ... Ergibt sich doch aber aus dem was in meinem Post stand ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.