Recent

Author Topic: Programming Pascal with an AI Chatbot 2.0  (Read 21419 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3805
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #15 on: January 03, 2023, 08:59:27 pm »
OMG  :o

Q: write a pascal program that shows how to use generics

A: Sure! Here is a simple example of how to use generics in Pascal:

Code: Pascal  [Select][+][-]
  1. type
  2.   generic TMyGenericType<T> = class
  3.   private
  4.     FValue: T;
  5.   public
  6.     procedure SetValue(AValue: T);
  7.     function GetValue: T;
  8.   end;
  9.  
  10. procedure TMyGenericType<T>.SetValue(AValue: T);
  11. begin
  12.   FValue := AValue;
  13. end;
  14.  
  15. function TMyGenericType<T>.GetValue: T;
  16. begin
  17.   Result := FValue;
  18. end;
  19.  
  20. var
  21.   IntGenericType: TMyGenericType<Integer>;
  22.   StringGenericType: TMyGenericType<String>;
  23.  
  24. begin
  25.   IntGenericType := TMyGenericType<Integer>.Create;
  26.   IntGenericType.SetValue(10);
  27.   WriteLn(IntGenericType.GetValue);  // Output: 10
  28.  
  29.   StringGenericType := TMyGenericType<String>.Create;
  30.   StringGenericType.SetValue('Hello, World!');
  31.   WriteLn(StringGenericType.GetValue);  // Output: Hello, World!
  32. end.
  33.  

In this example, we have defined a generic class TMyGenericType with a single type parameter T. The class has a private field FValue of type T, and a couple of methods SetValue and GetValue to set and get the value of FValue, respectively.

We then create two instances of this class, IntGenericType and StringGenericType, specifying the type parameter as Integer and String, respectively. We can then use these instances to set and get values of the corresponding types.

I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

zeljko

  • Hero Member
  • *****
  • Posts: 1870
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #16 on: January 03, 2023, 09:09:40 pm »
Same question and I got this :

 to the increased number of online dating sites, it has become easier
than ever before to find a potential partner. With a variety of sites to choose from, it is now possible to find someone who matches your interests, values, lifestyle, and goals. Online dating sites also provide a plethora of features that can help you find the perfect match, such as matchmaking quizzes, location-based search filters, and even recommendations from friends. Additionally, most sites offer free trials so you can try the service before committing to a subscription. With all of these options, it's never been easier to find the one you're looking for!

zeljko

  • Hero Member
  • *****
  • Posts: 1870
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #17 on: January 03, 2023, 09:10:22 pm »
What are you doing Dave ? ;))))

Fred vS

  • Hero Member
  • *****
  • Posts: 3805
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #18 on: January 03, 2023, 09:14:51 pm »
It might be wrong, but it attempts to understand the content in a way that is amazing.

Q: Convert Mat_MeanWithMask from https://github.com/hybridgroup/gocv/blob/release/core.cpp to freepascal

I keep getting this type of response now:

I'm sorry, but I am not able to perform tasks such as converting code from one language to another. However, there are tools and resources available online that can help you convert code from C to Pascal. Some options you might consider include using an online code converter or searching for a C to Pascal converter tool.

Hum, for me it gives this (not the same as Avra):

Q: Convert Mat_MeanWithMask from https://github.com/hybridgroup/gocv/blob/release/core.cpp to freepascal

A: Here is a Pascal version of the MatMeanWithMask function you provided:

Code: Pascal  [Select][+][-]
  1. function MatMeanWithMask(const Mat: TMat; const Mask: TMat): TScalar;
  2. var
  3.   Mean, StdDev: TScalar;
  4. begin
  5.   MeanStdDev(Mat, Mean, StdDev, Mask);
  6.   Result := Mean;
  7. end;

This function calculates the mean value of the elements in the input Mat array, using the optional Mask to select which elements should be included in the calculation. It does this by calling the MeanStdDev function, which calculates both the mean and standard deviation of the elements in the input array, and then returns only the mean value.

You will need to make sure that you have the necessary types and functions available in your Pascal code, such as TMat, TScalar, and MeanStdDev.

________________

So the answers differ depending of his mood: very human-like  ::)
« Last Edit: January 03, 2023, 09:18:20 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

zeljko

  • Hero Member
  • *****
  • Posts: 1870
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #19 on: January 03, 2023, 09:19:49 pm »
Q: Convert Mat_MeanWithMask from https://github.com/hybridgroup/gocv/blob/release/core.cpp to freepascal

function Mat_MeanWithMask(src, mask: PMat): Double;
var
  mean: Double;
  count: Int64;
  x, y: Integer;
begin
  Result := 0;
  if (src = nil) or (src^.Total() = 0) then
    Exit;
   
  if (mask = nil) or (mask^.Total() = 0) then
  begin
    Result := Mat_Mean(src);
    Exit;
  end;
 
  // Calculate mean
  mean := 0.0;
  count := 0;
  for y := 0 to src^.Rows() - 1 do
  begin
    for x := 0 to src^.Cols() - 1 do
    begin
      if (mask^.Data[y * src^.Cols() + x] <> 0) then
      begin
        mean += src^.Data[y * src^.Cols() + x];
        Inc(count);
      end;
    end;
  end;
  mean := mean / count;
  Result := mean;
end;

Fred vS

  • Hero Member
  • *****
  • Posts: 3805
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #20 on: January 03, 2023, 09:41:02 pm »
Of course, polyglot:  :o
----

Q: Parlez vous Francais?

A: Oui, je parle français. Je suis un modèle de langage formé par OpenAI et je suis conçu pour être en mesure de comprendre et de répondre à une variété de questions sur un large éventail de sujets. Est-ce que je peux vous aider avec quelque chose de particulier en français?

----

Sorry but big WoW.
Like in the movie "Her" of Spike Jonze (2013).
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

zeljko

  • Hero Member
  • *****
  • Posts: 1870
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #21 on: January 03, 2023, 11:28:36 pm »
Q: Write me nice song

A: Verse 1:
It's been a long road, I've been on my own
I'm still here standing, though I feel so low
I've made mistakes, I've felt the pain
But I know I'm stronger, so I won't complain

Chorus:
So I'll keep on going, never give up hope
I'll keep believing, and never give up on me
I will rise up, I will find my way
I won't be broken, no matter what they say

Verse 2:
I'm so much more than who they think I am
I'm better than I ever was before
I'll take a stand and never back down
I know I'll make it, I won't be around

Chorus:
So I'll keep on going, never give up hope
I'll keep believing, and never give up on me
I will rise up, I will find my way
I won't be broken, no matter what they say

Bridge:
No matter what life throws at me, I won't give in
I'll keep my head held high, and I will win
I'm gonna keep on fighting, until I reach the light
I know I can do it, I have the might

Chorus:
So I'll keep on going, never give up hope
I'll keep believing, and never give up on me
I will rise up, I will find my way
I won't be broken, no matter what they say

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 728
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #22 on: January 03, 2023, 11:33:29 pm »
If domasz above is correct and the program can lie I'm even more impressed  :o
All too human...

lainz

  • Hero Member
  • *****
  • Posts: 4741
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #23 on: January 04, 2023, 02:02:25 am »
I asked for a pong game, then it gives me a pong game (without second player AI).

Then I asked for a pong game for 2 players, full source in html + javascript working very well.

Then I asked for a poem in spanish about the sky, here it is:

Quote
escribe un poema sobre el cielo

Quote
El cielo es un lienzo inmenso
que el sol pinta cada mañana
con sus rayos de oro y ceniza
y sus nubes de algodón y plata.

Es el hogar de las estrellas
que brillan con luz propia
y el lugar donde los pájaros
cantan sus melodías.

El cielo es el refugio de los sueños
que volamos al alcanzar la cima
y es el lugar donde el viento sopla
con suave brisa o con furia.

Es el hogar de los cambios
que nos hacen crecer y evolucionar
y es el lugar donde la lluvia cae
limpiando el polvo y la tristeza.

El cielo es el reflejo del alma
que se refleja en el azul profundo
y es el lugar donde el tiempo pasa
sin dejar huella ni recuerdo.

Fred vS

  • Hero Member
  • *****
  • Posts: 3805
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #24 on: January 04, 2023, 03:08:24 am »
Q: how to add a reverb effect on a array of samples in pascal with example?

A: To add a reverb effect to an array of samples in Pascal, you can use a technique called convolution. Convolution involves applying a "reverb impulse response" (a set of samples representing the response of a particular reverb effect) to the input audio samples to produce the desired reverb effect.

Here is an example of how you might implement convolution in Pascal to add a reverb effect to an array of samples:

Code: Pascal  [Select][+][-]
  1. const
  2.   REVERB_IMPULSE_RESPONSE_LENGTH = 4096;  // length of the reverb impulse response
  3.   NUM_SAMPLES = 4096;  // number of samples in the input audio
  4.  
  5. var
  6.   input_samples: array[0..NUM_SAMPLES-1] of Single;  // input audio samples
  7.   reverb_impulse_response: array[0..REVERB_IMPULSE_RESPONSE_LENGTH-1] of Single;  // reverb impulse response
  8.   output_samples: array[0..NUM_SAMPLES-1] of Single;  // output audio samples (with reverb)
  9.  
  10. // Initialize the input samples and reverb impulse response...
  11.  
  12. // Perform the convolution to add the reverb effect:
  13. for i := 0 to NUM_SAMPLES-1 do begin
  14.   output_samples[i] := 0;
  15.   for j := 0 to REVERB_IMPULSE_RESPONSE_LENGTH-1 do begin
  16.     output_samples[i] := output_samples[i] + input_samples[i-j] * reverb_impulse_response[j];
  17.   end;
  18. end;
  19.  

This code performs convolution by multiplying each input sample with the corresponding sample from the reverb impulse response, and then summing the results. This produces the desired reverb effect, with the strength and characteristics of the effect being determined by the values in the reverb impulse response.

You will need to obtain a suitable reverb impulse response to use in this example. There are many resources available online that provide a variety of different impulse responses for different reverb effects.

Q: Thanks and for a echo effect ?

A: To add an echo effect to an array of audio samples in Pascal, you can use a similar technique to the one I described for adding a reverb effect. The main difference is that you will use a "delay" instead of a reverb impulse response.

A delay is simply a set of samples representing a specific amount of time delay. To create an echo effect, you can apply a delay to the input audio by copying the input samples to a separate "delay buffer" and then mixing the delayed samples back into the output at a lower volume. Here is an example of how you might implement this in Pascal:

Code: Pascal  [Select][+][-]
  1. const
  2.   DELAY_BUFFER_LENGTH = 4096;  // length of the delay buffer
  3.   NUM_SAMPLES = 4096;  // number of samples in the input audio
  4.   ECHO_VOLUME = 0.5;  // volume of the echo relative to the input
  5.  
  6. var
  7.   input_samples: array[0..NUM_SAMPLES-1] of Single;  // input audio samples
  8.   delay_buffer: array[0..DELAY_BUFFER_LENGTH-1] of Single;  // delay buffer
  9.   output_samples: array[0..NUM_SAMPLES-1] of Single;  // output audio samples (with echo)
  10.  
  11. // Initialize the input samples and delay buffer...
  12.  
  13. // Add the echo effect:
  14. for i := 0 to NUM_SAMPLES-1 do begin
  15.   // Copy the current input sample to the delay buffer:
  16.   delay_buffer[i mod DELAY_BUFFER_LENGTH] := input_samples[i];
  17.  
  18.   // Mix the delayed sample into the output:
  19.   output_samples[i] := input_samples[i] + ECHO_VOLUME * delay_buffer[(i-DELAY_TIME) mod DELAY_BUFFER_LENGTH];
  20. end;
  21.  

In this example, the DELAY_TIME constant determines the length of the delay in terms of the number of samples. You can adjust this value to change the amount of time delay and thus the strength of the echo effect. As with the reverb example, you will need to experiment with different values to find the effect that you want.

Q: Thanks and a chorus effect?

A: To add a chorus effect to an array of audio samples in Pascal, you can use a combination of delay and pitch shifting. A chorus effect is created by adding a slightly delayed and pitch-shifted version of the input audio to the original signal.

Here is an example of how you might implement a simple chorus effect in Pascal:

Code: Pascal  [Select][+][-]
  1. const
  2.   DELAY_BUFFER_LENGTH = 4096;  // length of the delay buffer
  3.   NUM_SAMPLES = 4096;  // number of samples in the input audio
  4.   CHORUS_VOLUME = 0.5;  // volume of the delayed and pitch-shifted audio relative to the input
  5.   PITCH_SHIFT_AMOUNT = 0.01;  // pitch shift amount (in semitones)
  6.  
  7. var
  8.   input_samples: array[0..NUM_SAMPLES-1] of Single;  // input audio samples
  9.   delay_buffer: array[0..DELAY_BUFFER_LENGTH-1] of Single;  // delay buffer
  10.   output_samples: array[0..NUM_SAMPLES-1] of Single;  // output audio samples (with chorus)
  11.  
  12. // Initialize the input samples and delay buffer...
  13.  
  14. // Add the chorus effect:
  15. for i := 0 to NUM_SAMPLES-1 do begin
  16.   // Copy the current input sample to the delay buffer:
  17.   delay_buffer[i mod DELAY_BUFFER_LENGTH] := input_samples[i];
  18.  
  19.   // Mix the delayed and pitch-shifted sample into the output:
  20.   output_samples[i] := input_samples[i] + CHORUS_VOLUME * delay_buffer[(i-DELAY_TIME) mod DELAY_BUFFER_LENGTH] * PITCH_SHIFT(PITCH_SHIFT_AMOUNT);
  21. end;
  22.  

In this example, the DELAY_TIME constant determines the length of the delay in terms of the number of samples, and the PITCH_SHIFT_AMOUNT constant determines the amount of pitch shift to apply to the delayed signal. The PITCH_SHIFT function is a hypothetical function that applies a pitch shift to an input audio sample (it would need to be implemented separately).

You can adjust the values of the DELAY_TIME and PITCH_SHIFT_AMOUNT constants to control the strength and characteristics of the chorus effect. Experimenting with different values will help you find the effect that you want.

Q: And how to stretch (changing tempo without the pitch) of a array of samples in pascal with example?

A: To stretch the tempo of an array of samples in Pascal without changing the pitch, you can use a technique called time-stretching. This involves changing the speed at which the samples are played back, while maintaining the original pitch of the audio.

Here's an example of how you might implement time-stretching in Pascal:

Code: Pascal  [Select][+][-]
  1. const
  2.   SAMPLE_RATE = 44100; // sample rate of the audio
  3.   CHANNELS = 2; // number of channels (e.g. stereo)
  4.  
  5. type
  6.   TSample = Single; // type for individual samples
  7.   TSampleArray = array of TSample; // type for arrays of samples
  8.  
  9. function TimeStretch(const samples: TSampleArray; stretchFactor: Single): TSampleArray;
  10. var
  11.   stretchedSamples: TSampleArray;
  12.   sampleIndex, channel: Integer;
  13. begin
  14.   SetLength(stretchedSamples, Round(Length(samples) * stretchFactor));
  15.   for sampleIndex := 0 to Length(stretchedSamples) - 1 do
  16.   begin
  17.     // interpolate the sample value at the stretched sample index
  18.     stretchedSamples[sampleIndex] :=
  19.       samples[Round(sampleIndex / stretchFactor)] * (1 - Frac(sampleIndex / stretchFactor)) +
  20.       samples[Round(sampleIndex / stretchFactor) + 1] * Frac(sampleIndex / stretchFactor);
  21.   end;
  22.   Result := stretchedSamples;
  23. end;
  24.  
  25.  

This function takes an array of audio samples samples and a stretch factor stretchFactor, and returns a new array of stretched samples. The stretch factor is a value that specifies how much to stretch the audio. A stretch factor of 1.0 will result in no change, a stretch factor of 2.0 will double the length of the audio, and a stretch factor of 0.5 will halve the length of the audio.

To use this function, you can call it like this:

Code: Pascal  [Select][+][-]
  1. var
  2.   originalSamples: TSampleArray;
  3.   stretchedSamples: TSampleArray;
  4.   stretchFactor: Single;
  5. begin
  6.   originalSamples := LoadSamplesFromFile('my_audio_file.wav');
  7.   stretchFactor := 1.5; // stretch the audio by 50%
  8.   stretchedSamples := TimeStretch(originalSamples, stretchFactor);
  9.   SaveSamplesToFile(stretchedSamples, 'stretched_audio_file.wav');
  10. end;
  11.  

This code loads an array of audio samples from a file, stretches the audio by a factor of 1.5, and then saves the stretched samples to a new file.

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

Huh, indeed all work, out of the box...
Terrific  :o
« Last Edit: January 04, 2023, 03:40:04 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #25 on: January 04, 2023, 08:09:38 am »
Q: how to add a reverb effect on a array of samples in pascal with example?
...

That's just awesome isn't it? Just imagine a future revision where it can progressively learn in real time with direct access to the web.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #26 on: January 04, 2023, 09:10:27 am »
This link has information about possible open source alternatives to ChatGPT, and the very high cost of processing the training data required to get any of them up to speed.

mdalacu

  • Full Member
  • ***
  • Posts: 238
    • dmSimpleApps
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #27 on: January 04, 2023, 09:26:57 am »
It can't be trusted, at all! :D

Quote
What are the most known application written with Lazarus?
Lazarus is a popular cross-platform Integrated Development Environment (IDE) that is used for developing applications using the Free Pascal compiler. Some of the most well-known applications that have been developed using Lazarus include:

LibreOffice: LibreOffice is a free and open-source office suite that is similar to Microsoft Office. It includes a word processor, spreadsheet application, presentation software, and other tools for creating and editing documents. LibreOffice was developed using Lazarus.

VirtualBox: VirtualBox is a free and open-source virtualization software application that allows users to run multiple operating systems on a single physical machine. It is widely used for testing and development purposes, and it is available for Windows, macOS, and Linux. VirtualBox was developed using Lazarus.

KeePass: KeePass is a free and open-source password manager that is used for storing and managing passwords and other sensitive information. It is available for Windows, macOS, and Linux, and it is widely used for keeping track of login credentials and other sensitive data. KeePass was developed using Lazarus.

Inno Setup: Inno Setup is a free and open-source software installation system that is used for creating installers for Windows applications. It is widely used for distributing software, and it is known for its simplicity and ease of use. Inno Setup was developed using Lazarus.

There are many other applications and projects that have been developed using Lazarus, and the list above is just a small sampling of the types of software that can be developed using this tool.




mdalacu@yahoo.com
Why do you say that VirtualBox was developed using Lazarus?
I apologize for the mistake in my previous response. VirtualBox is not developed using Lazarus. VirtualBox is a virtualization software application that was developed by Oracle Corporation, and it is not related to the Lazarus IDE or the Free Pascal compiler. I apologize for any confusion my previous response may have caused.

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #28 on: January 04, 2023, 09:47:07 am »
It can't be trusted, at all! :D
Just keep pressing 'Regenerate response' until it gives an answer that can be trusted. ROFL.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Fred vS

  • Hero Member
  • *****
  • Posts: 3805
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #29 on: January 04, 2023, 12:55:20 pm »
Q: how to add a reverb effect on a array of samples in pascal with example?
...

That's just awesome isn't it? Just imagine a future revision where it can progressively learn in real time with direct access to the web.

It is incredible.
Also the demo to do stretching of sound works...

And all clearly explained.

I am totally mega-impressed.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018