نمایش نتایج 1 تا 6 از 6

نام تاپیک: نواختن نتهای موسیقی توسط کد نویسی

  1. #1

    نواختن نتهای موسیقی توسط کد نویسی

    سلام

    در این تاپیک در مورد معرفی ابزار و کتابخانه ها و نحوه ی کد نویسی برای نواختن فایلهای midi و نتهای موسیقی صحبت خواهد شد.

    در پاسخ به سئوال یکی از دوستان در تالار VB.net : البته چون این قضیه به زبان برنامه نویسی مربوط نمیشه و از طرفی در این زمینه هم تاپیک مشخصی وجود نداشت من این تاپیک رو بصورت مستقل در این تالار ایجاد میکنم.‌

    نقل قول نوشته شده توسط kamranKoohi مشاهده تاپیک
    سلام
    لطفا اگر کسی میدونه که نت های موسیقی رو (........do,re,me) چطور میشه اجرا کرد ممنون
    میشم اگه یک مثال بزنه.
    با تشکر بسیار
    در پایان ممنون میشم اگه دوستان نیز نظرشون رو اعلام کنند.
    ...مرا به خانه ام ببر، اگرچه خانه؛ خانه نیست

  2. #2
    اینجا رو ببینید : (یک مثال به زبان VB.net است)


    http://www.codeproject.com/KB/audio-...rdPackage.aspx

    مثال بالا، از یکی از توابع API ویندوز(KERNEL32.DLL) بنام Beep استفاده کرده که ساده ترین روش ممکنه (اما با کیفیت پایین) و فقط کافیه که یک فرکانس و زمان کشش نت رو بهش بدید :

    <DllImport("KERNEL32.DLL")> _
    Public Shared Sub Beep(ByVal freq As Integer, ByVal dur As Integer)
    End Sub

    در مورد عدد فرکانس نت ها باید جستجو کنید. تا اونجا که من یادم میاد : مثلا برای نت "لا" اکتاو سوم عدد 440 بود و برای اکتاو چهارم عدد 880 و ...



    برای داشتن کیفیت بهتر باید از توابع مخصوص midi در DirectMusic (یکی از مولفه های DirectX) استفاده کنید. که البته اون هم مزایا و معایب خودش رو داره :
    http://www.codeproject.com/KB/audio-video/mididemocp.aspx
    Advantages of using DirectX to play Midi
    1. If you select the DirectX Microsoft Synthesizer (default device) it will be possible that multiple applications can play Midi at once.
    2. If you have a very CHEAP sound card, the Microsoft Synthesizer will sound better than the driver of your soundcard.
    Disadvantages of using DirectX to play Midi
    1. Every user of your software needs to have DirectX installed. On Windows 95 and NT he will always have to update Direct X. Users of Windows 98 and 2000 will also need to update DirectX if your application requires DirectX 7 or 8. The download of DirectX is unacceptable for modem users (> 12 Megabyte)
    2. The documentation of DirectX in the MSDN is poor, poor, poor ! And if you even want to write for an older DirectX version (like 5 or 6) to allow users of Windows 98 and 2000 to use your application without updating DirectX you will find NOTHING about that in the actual MSDN ! Microsoft completely removed the older documentations !
    3. When your application initializes DirectX a dozen of DLLs is loaded which consume about 4 Megabytes of RAM. On a Pentium 100 this loading of DLLs takes 3 seconds.
    4. After playing a Midi file DirectX does NOT automatically free the used Midi device. This means that other applications (e.g. WinAmp) can NOT access it. Your software has to take care to remove the port after playing the file. The problem is that the sound is played asynchronously and you don't know when DirectX will finish to play. To find out in advance the length of a Midi sound is very complicated because the tempo can change multiple times in a Midi file. So you could check with a timer in certain intervals if the sound is still playing (IDirectMusicPerformance::IsPlaying()) and than remove the port - but this is awkward !
    5. If you have a middle-class or a good soundcard (like Soundblaster live) you will find that the Microsoft Synthesizer (default device) sounds awful ! You have to insert extra code (IDirectMusic::EnumPort()), a combo box, code to store the user settings etc. to allow the user to choose a Midi device, which sounds better. My cSound class does not need that because it uses the device, which the user has selected in the Control Panel.


    اینا رو هم ببینید (بد نیست) :
    http://www.codeproject.com/KB/audio-video/synthtoolkitparti.aspx
    http://www.codeproject.com/KB/audio-...midiports.aspx
    http://www.codeproject.com/KB/audio-...DIToolkit.aspx

    ...مرا به خانه ام ببر، اگرچه خانه؛ خانه نیست

  3. #3
    به نقل از :‌ http://www.borg.com/~jglatt/tech/winapi.htm


    Low level API

    The "low level" Windows functions are called that because they require that your program does a lot of the work of recording/playing MIDI and Digital Audio data, short of actually manipulating the sound card hardware. For example, if you want to play a MIDI file (ie, play a musical sequence), then you have to load the MIDI data contained within that file, use a (Windows software) timer to determine when it is time to output each MIDI message, and when that time occurs, pass that message (ie, its data bytes) to a Windows function that actually outputs the bytes.
    If you want to record a MIDI file, then you have to tell Windows to notify you when the card's driver has input the next MIDI message and to request Windows to pass you those MIDI data bytes, use a (Windows software) timer to timestamp that MIDI message, and write the bytes to disk (typically in MIDI File Format).
    Because your program does most of the work, you have a lot of control over the playback/recording process, such as the ability to vary tempo, or perform filtering/mixing/transposing/etc of data on-the-fly.
    For a more indepth discussion of writing a program that uses the Low level MIDI functions, see Low level MIDI API.
    There are also low level functions for Digital Audio. Again, these require that you do a lot of work to record/play the digital audio data.
    For example, if you want to play a WAVE file (ie, play digital audio), then you have to load the digital audio data contained within that file in "blocks" (ie, usually filling a buffer of 4K of data at a time), and feed it to a Windows function that actually outputs the data. In order to get a smooth, continuous playback of digital audio, you typically have to do double-buffering (ie, while the card is playing back one buffer of 4K data, you need to be simultaneously filling a second buffer with the next 4K of data).
    If you want to record a WAVE file, then Windows has to feed you a continuous stream of those blocks of data, and you must write each block to disk (typically in WAVE File Format). In order to get a smooth, continuous recording of digital audio, you typically have to do double-buffering (ie, while the card is recording one buffer of 4K data, you need to be simultaneously writing the buffer containing the previous 4K of data to disk).
    For a more indepth discussion of writing a program that uses the Low level Digital Audio functions, see Low level Digital Audio API.
    High level API

    The "high level" Windows functions are called that because they relieve your program of a lot of the burden of recording/playing MIDI and Digital Audio data. For example, if you want to play a MIDI file (ie, play a musical sequence), then you merely call one Windows function, specifying the name of the MIDI file to be played back. Windows will open the MIDI file and load the MIDI data contained within that file, use a (Windows software) timer to determine when it is time to output each MIDI message, and actually output the bytes. In other words, Windows plays the MIDI file in the background while your program can go on to do other things simultaneously.
    If you want to record a MIDI file, then you merely call one Windows function, specifying the name of the MIDI file to be created. Again, Windows does all of the work of reading the incoming MIDI data, time-stamping each message, and writing the data to disk in MIDI File Format. (NOTE: At this time, Windows does not offer High level API support for MIDI recording).
    But because your program doesn't do most of the work, you lose a lot of control over the playback/recording process, such as being able to perform filtering of data on-the-fly, etc. You're pretty much limited to being able to stop, start, pause, rewind, and fast-forward the playback.
    For a more indepth discussion of writing a program that uses the High level MIDI functions, see High level MIDI API.
    There is also a high level API for playing/recording WAVE files. Just like with the High level MIDI API, Windows does a lot of the work (ie, completely loads and plays the WAVE file in the background), but again, you lose a lot of control over the actual playback (for example being able to do on-the-fly mixing of digital audio -- to implement virtual tracks. For a more indepth discussion of virtual tracks, see the article Digital Audio on a computer).
    For a more indepth discussion of writing a program that uses the High level Digital Audio functions, see High level Digital Audio API.
    A new, "inbetween" MIDI API

    A further option for MIDI sequencing (ie, the playback of musical excerpts using MIDI events) under Win95/98/ME/2000/XP and WinNT (4.X and above only) is to use the Stream API. This allows you to store a MIDI message in a special structure that contains a field that specifies the amount of time to delay before outputting the MIDI message. Windows does the actual timing of the MIDI playback. Unlike with the High level MIDI API, you still load the MIDI data and feed each message (or more likely a block of messages) to Windows (ie, so you have more control over the playback on a per-message basis), but you no longer have to time the playback. In other words, the Stream API is useful for playing back musical sequences where you still have a lot of control over individual events and can therefore perform various filtering and modification of MIDI data on-the-fly, but don't want to deal with timing issues (which is particularly aggravating under Win95/98/ME due to the timing discrepancies of 32-bit MultiMedia Timer callbacks). Currently, the Stream API supports playback only (not recording -- ie, it can't supply you with time-stamped incoming MIDI messages). So, if you need to do MIDI recording, you'll have to use the Low level MIDI API and a MultiMedia Timer, or use DirectMusic.
    For a more indepth discussion of writing a program that uses the MIDI Stream functions, see MIDI Stream API.
    A new, fancier Digital Audio API

    Many game programs use lots of digital audio for sound effects, and various waveforms often have to be mixed on-the-fly. For this purpose, Microsoft devised a new set of functions called "DirectSound" (ie, part of DirectX) under Win95/98/ME/2000/XP and WinNT (4.X and above only). These functions let the operating system take care of mixing several waveforms to a sound card's stereo DAC.
    DirectX versions prior to 6.1 support playback, but not recording.
    A card's device driver should have extra support to work well with the DirectSound API (although older drivers not directly supporting DirectSound may work with this API albeit very inefficiently and/or with some features disabled).
    For a more indepth discussion of writing a program that uses the DirectSound functions, see DirectSound API.
    A new, less archaic MIDI API

    Many game programs also use MIDI for background music. For this purpose, Microsoft devised a new set of functions called "DirectMusic" (ie, part of DirectX) under Win95/98/ME/2000/XP and WinNT (4.X and above only). These functions are a bit newer than the older low level MIDI API, and address some of the oddities/discrepancies that plague the legacy MIDI API.
    DirectX versions prior to 6.0 do not include DirectMusic, and versions prior to 6.1 support only playback.
    A card's device driver should have extra support to work well with the DirectMusic API (although older drivers not directly supporting DirectMusic may work with this API albeit very inefficiently and/or with some features disabled).
    For a more indepth discussion of writing a program that uses the DirectMusic functions, see DirectMusic API.
    Miscellaneous Functions (ie, the Mixer API, and Aux API)

    The Mixer API has functions to get a listing of all of the various inputs and outputs on a particular card (ie, how many Aux inputs, Line inputs, Mic inputs, Line outputs, etc, it has), and to adjust all of the volumes of these various components, as well as perform other operations such as muting inputs. This is a new API added to Win95/98/ME/2000/XP and WinNT (4.X and above only). A card's device driver needs extra support to work with the Mixer API. Not all Windows drivers have this support. Win3.1 drivers do not.
    For a more indepth discussion of writing a program that uses the Mixer functions, see Mixer API.
    Older drivers should at least support the Aux API. Just like with the lists for devices that support MIDI input and output, and Digital Audio playback and recording, Windows maintains a list of all devices that have Aux outputs. (And again, a card's device driver instructs Windows to put some name into this list). The Aux functions allow a program to control the volume (and perhaps other settings) of each Aux output. Typically, audio from a CDROM or the audio output of a voice modem is connected to a sound card's Aux output. (ie, So, it's the volume of these that you're affecting).
    For a more indepth discussion of writing a program that uses the Aux functions, see Aux API.
    MultiMedia File functions

    When programs use the low level MIDI and Digital Audio API, they typically have to open, read, and write MIDI and WAVE File Format files. To help parse Interchange File Format types of files (ie, files whose data is arranged into nested chunks), Windows has a MultiMedia File (ie, Mmio) API. For a more indepth discussion of writing a program that uses the MultiMedia File API, see MultiMedia File API.
    Misc Topics

    The following online Windows book is available for download. It gives more information about the Windows MIDI and digital audio functions (as well as Aux API and MultiMedia Timer API). But note that this book dates back to Windows 3.1, so some newer features, APIs, and notes may be omitted. Use the tutorials on this site for more uptodate information. Windows MultiMedia System Book
    ...مرا به خانه ام ببر، اگرچه خانه؛ خانه نیست

  4. #4
    در این پست نحوه دیگری از نواختن نتهای موسیقی رو توسط یک مثال بسیار ساده از VB6 (البته باز هم تکرار میکنم که به دلیل استفاده از کتابخانه های سیستمی یکسان و مشترک، زبان برنامه نویسی بکار رفته اهمیت چندانی ندارد ) مشاهده میکنید که از کتابخانه winmm.dll ویندوز استفاده میکند.
    این کتابخانه حاوی فانکشنهایی است که از جمله مهمترین های آن در مورد این مثال میتوان به midiOutOpen (جهت باز کردن یک وسیله خروجی Midi) و midiOutShortMsg (جهت ارسال یک پیغام Midi کوچک به یک وسیله خروجی Midi مشخص) اشاره کرد :

    Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
    ' This function sends a short MIDI message to the specified MIDI output device. The function
    ' requires the handle to the MIDI output device and a message is packed into a doubleword
    ' value with the first byte of the message in the low-order byte. See the code sample for
    ' how to create this value.
    winmm.dll is a module for the Windows Multimedia API, which contains low-level audio and joystick functions.


    برای مشاهده سایر توابع این کتابخانه به این آدرس مراجعه نمایید :‌
    http://source.winehq.org/WineAPI/winmm.html
    فایل های ضمیمه فایل های ضمیمه
    ...مرا به خانه ام ببر، اگرچه خانه؛ خانه نیست

  5. #5
    در ضمن در مورد طرز استفاده از کد ها ئی که با C نوشته شده اند هم در VB کمی بیشتر توضیح بده . چون نتونسم ار اونا در vb استفاده کنم.
    (البته باز هم تکرار میکنم که به دلیل استفاده از کتابخانه های سیستمی یکسان و مشترک، زبان برنامه نویسی بکار رفته اهمیت چندانی ندارد )
    آخرین ویرایش به وسیله omid_Ahmadi : شنبه 22 دی 1386 در 18:10 عصر دلیل: سوالات جدید رو در تاپیک جدید بپرس

  6. #6
    کاربر دائمی آواتار jeus
    تاریخ عضویت
    آبان 1385
    محل زندگی
    لباسام
    پست
    317

    نقل قول: نواختن نتهای موسیقی توسط کد نویسی

    دوستان سئوالی دارم و اینه که آیا در برنامه هایی مانند کراک و patch نرم افزارها که معمولا همراه با باز شدن به نواختن موسیقی میپردازند آیا از همین روش استفاده شده و نتها به ترتیب درون برنامه قرار گرفته اند ؟

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •